目录
配置步骤
整体过程
1.配置步骤
2.装包
3.修改配置文件
4.启动配置文件
5.检查相应的配置
6.进入数据库
7.关闭mongodb命令
mongodb严格区分大小写
装包
修改配置文件
启动配置文件
检查相应的配置
[root@51 ~]# tar -zxf mongodb-linux-x86_64-rhel70-3.6.3.tgz ----免安装,解压 [root@51 ~]# ls mongodb-linux-x86_64-rhel70-3.6.3 bin GNU-AGPL-3.0 MPL-2 README THIRD-PARTY-NOTICES [root@51 ~]# ls mongodb-linux-x86_64-rhel70-3.6.3/bin/ bsondump mongod mongofiles mongoreplay mongostat install_compass mongodump mongoimport mongorestore mongotop mongo mongoexport mongoperf mongos [root@51 ~]# mkdir /usr/local/mongodb ----创建一个文件夹存放mongodb的相关文件 [root@51 ~]# mv mongodb-linux-x86_64-rhel70-3.6.3/bin /usr/local/mongodb/ --把mongodb放入系统命令文件内 [root@51 ~]# ls /usr/local/mongodb/bin/ bsondump mongod mongofiles mongoreplay mongostat install_compass mongodump mongoimport mongorestore mongotop mongo mongoexport mongoperf mongos [root@51 ~]# cd /usr/local/mongodb/ [root@51 mongodb]# ls bin [root@51 mongodb]# mkdir etc ----在创建的文件夹下创建mongodb需要存放配置文件 [root@51 mongodb]# mkdir log ----在创建的文件夹下创建mongodb需要存放的日志文件 [root@51 mongodb]# ls bin etc log [root@51 mongodb]# mkdir -p data/db ----在创建的文件夹下创建mongodb需要存放数据库
默认端口2717 [root@51 mongodb]# vim etc/mongodb.conf [root@51 mongodb]# cat etc/mongodb.conf dbpath=/usr/local/mongodb/data/db ----指定数据存放的路径 fork=true -----开启守护进程的方式 logpath=/usr/local/mongodb/log/mongodb.log -----添加日志存放的路径 logappend=true bind_ip=192.168.4.51 port=27051 [root@51 mongodb]# pwd /usr/local/mongodb [root@51 mongodb]# ls bin data etc log [root@51 mongodb]# vim /etc/pro profile profile.d/ protocols
[root@51 mongodb]# vim /etc/profile
export PATH=/usr/local/mongodb/bin:$PATH
[root@51 mongodb]# source /etc/profile [root@51 mongodb]# mongo mongo mongoexport mongoperf mongos mongod mongofiles mongoreplay mongostat mongodump mongoimport mongorestore mongotop [root@51 mongodb]# echo $PATH /usr/local/mongodb/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
[root@51 mongodb]# mongod -f /usr/local/mongodb/etc/mongodb.conf about to fork child process, waiting until server is ready for connections. forked process: 2824 child process started successfully, parent exiting
[root@51 mongodb]# mongod -f /usr/local/mongodb/etc/mongodb.conf --启动mongodb about to fork child process, waiting until server is ready for connections. forked process: 2824 child process started successfully, parent exiting [root@51 mongodb]# ls /usr/local/mongodb/ bin data etc log [root@51 mongodb]# ls /usr/local/mongodb/log/ -----查看日志文件是否存在 mongodb.log [root@51 mongodb]# cat /usr/local/mongodb/log/mongodb.log -----查看日志文件是否存在 2018-07-07T10:49:35.877+0800 I CONTROL [initandlisten] MongoDB starting : pid=2824 port=27017 dbpath=/usr/local/mongodb/data/db 64-bit host=51 2018-07-07T10:49:35.877+0800 I CONTROL [initandlisten] db version v3.6.3 2018-07-07T10:49:35.877+0800 I CONTROL [initandlisten] git version: 9586e557d54ef70f9ca4b43c26892cd55257e1a5 2018-07-07T10:49:35.877+0800 I CONTROL [initandlisten] OpenSSL version: OpenSSL 1.0.1e-fips 11 Feb 2013 2018-07-07T10:49:35.877+0800 I CONTROL [initandlisten] allocator: tcmalloc 2018-07-07T10:49:35.877+0800 I CONTROL [initandlisten] modules: none 2018-07-07T10:49:35.877+0800 I CONTROL [initandlisten] build environment: 2018-07-07T10:49:35.877+0800 I CONTROL [initandlisten] distmod: rhel70 2018-07-07T10:49:35.877+0800 I CONTROL [initandlisten] distarch: x86_64 2018-07-07T10:49:35.877+0800 I CONTROL [initandlisten] target_arch: x86_64 2018-07-07T10:49:35.877+0800 I CONTROL [initandlisten] options: { config: "/usr/local/mongodb/etc/mongodb.conf", processManagement: { fork: true }, storage: { dbPath: "/usr/local/mongodb/data/db" }, systemLog: { destination: "file", logAppend: true, path: "/usr/local/mongodb/log/mongodb.log" } } 2018-07-07T10:49:35.879+0800 I STORAGE [initandlisten] wiredtiger_open config: create,cache_size=256M,session_max=20000,eviction=(threads_min=4,threads_max=4),config_base=false,statistics=(fast),log=(enabled=true,archive=true,path=journal,compressor=snappy),file_manager=(close_idle_time=100000),statistics_log=(wait=0),verbose=(recovery_progress), 2018-07-07T10:49:37.104+0800 I CONTROL [initandlisten] 2018-07-07T10:49:37.104+0800 I CONTROL [initandlisten] ** WARNING: Access control is not enabled for the database. 2018-07-07T10:49:37.104+0800 I CONTROL [initandlisten] ** Read and write access to data and configuration is unrestricted. 2018-07-07T10:49:37.104+0800 I CONTROL [initandlisten] ** WARNING: You are running this process as the root user, which is not recommended. 2018-07-07T10:49:37.105+0800 I CONTROL [initandlisten] 2018-07-07T10:49:37.105+0800 I CONTROL [initandlisten] ** WARNING: This server is bound to localhost. 2018-07-07T10:49:37.105+0800 I CONTROL [initandlisten] ** Remote systems will be unable to connect to this server. 2018-07-07T10:49:37.105+0800 I CONTROL [initandlisten] ** Start the server with --bind_ip <address> to specify which IP 2018-07-07T10:49:37.105+0800 I CONTROL [initandlisten] ** addresses it should serve responses from, or with --bind_ip_all to 2018-07-07T10:49:37.105+0800 I CONTROL [initandlisten] ** bind to all interfaces. If this behavior is desired, start the 2018-07-07T10:49:37.105+0800 I CONTROL [initandlisten] ** server with --bind_ip 127.0.0.1 to disable this warning. 2018-07-07T10:49:37.105+0800 I CONTROL [initandlisten] 2018-07-07T10:49:37.106+0800 I CONTROL [initandlisten] 2018-07-07T10:49:37.106+0800 I CONTROL [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/enabled is 'always'. 2018-07-07T10:49:37.106+0800 I CONTROL [initandlisten] ** We suggest setting it to 'never' 2018-07-07T10:49:37.106+0800 I CONTROL [initandlisten] 2018-07-07T10:49:37.106+0800 I CONTROL [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/defrag is 'always'. 2018-07-07T10:49:37.106+0800 I CONTROL [initandlisten] ** We suggest setting it to 'never' 2018-07-07T10:49:37.106+0800 I CONTROL [initandlisten] 2018-07-07T10:49:37.107+0800 I STORAGE [initandlisten] createCollection: admin.system.version with provided UUID: 99867136-8b54-4536-a108-2f8809fb0926 2018-07-07T10:49:37.280+0800 I COMMAND [initandlisten] setting featureCompatibilityVersion to 3.6 2018-07-07T10:49:37.287+0800 I STORAGE [initandlisten] createCollection: local.startup_log with generated UUID: eacd06c8-7f17-44c4-9718-827884bc4527 2018-07-07T10:49:37.445+0800 I FTDC [initandlisten] Initializing full-time diagnostic data capture with directory '/usr/local/mongodb/data/db/diagnostic.data' 2018-07-07T10:49:37.446+0800 I NETWORK [initandlisten] waiting for connections on port 27017 [root@51 mongodb]# ls /usr/local/mongodb/ bin data etc log [root@51 mongodb]# ls /usr/local/mongodb/data/ db [root@51 mongodb]# ls /usr/local/mongodb/data/db/ collection-0--6955059650770541092.wt journal WiredTiger collection-2--6955059650770541092.wt _mdb_catalog.wt WiredTigerLAS.wt diagnostic.data mongod.lock WiredTiger.lock index-1--6955059650770541092.wt sizeStorer.wt WiredTiger.turtle index-3--6955059650770541092.wt storage.bson WiredTiger.wt [root@51 mongodb]# ss -utlpn | grep 27017 tcp LISTEN 0 128 127.0.0.1:27017 *:* users:(("mongod",pid=2824,fd=11)) [root@51 mongodb]# ps -C monGOD PID TTY TIME CMD [root@51 mongodb]# ps -C mongod PID TTY TIME CMD 2824 ? 00:00:01 mongod
[root@51 mongodb]# mongo MongoDB shell version v3.6.3 connecting to: mongodb://127.0.0.1:27017 MongoDB server version: 3.6.3 Welcome to the MongoDB shell. For interactive help, type "help". For more comprehensive documentation, see http://docs.mongodb.org/ Questions? Try the support group http://groups.google.com/group/mongodb-user Server has startup warnings: 2018-07-07T10:49:37.104+0800 I CONTROL [initandlisten] 2018-07-07T10:49:37.104+0800 I CONTROL [initandlisten] ** WARNING: Access control is not enabled for the database. 2018-07-07T10:49:37.104+0800 I CONTROL [initandlisten] ** Read and write access to data and configuration is unrestricted. 2018-07-07T10:49:37.104+0800 I CONTROL [initandlisten] ** WARNING: You are running this process as the root user, which is not recommended. 2018-07-07T10:49:37.105+0800 I CONTROL [initandlisten] 2018-07-07T10:49:37.105+0800 I CONTROL [initandlisten] ** WARNING: This server is bound to localhost. 2018-07-07T10:49:37.105+0800 I CONTROL [initandlisten] ** Remote systems will be unable to connect to this server. 2018-07-07T10:49:37.105+0800 I CONTROL [initandlisten] ** Start the server with --bind_ip <address> to specify which IP 2018-07-07T10:49:37.105+0800 I CONTROL [initandlisten] ** addresses it should serve responses from, or with --bind_ip_all to 2018-07-07T10:49:37.105+0800 I CONTROL [initandlisten] ** bind to all interfaces. If this behavior is desired, start the 2018-07-07T10:49:37.105+0800 I CONTROL [initandlisten] ** server with --bind_ip 127.0.0.1 to disable this warning. 2018-07-07T10:49:37.105+0800 I CONTROL [initandlisten] 2018-07-07T10:49:37.106+0800 I CONTROL [initandlisten] 2018-07-07T10:49:37.106+0800 I CONTROL [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/enabled is 'always'. 2018-07-07T10:49:37.106+0800 I CONTROL [initandlisten] ** We suggest setting it to 'never' 2018-07-07T10:49:37.106+0800 I CONTROL [initandlisten] 2018-07-07T10:49:37.106+0800 I CONTROL [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/defrag is 'always'. 2018-07-07T10:49:37.106+0800 I CONTROL [initandlisten] ** We suggest setting it to 'never' 2018-07-07T10:49:37.106+0800 I CONTROL [initandlisten] > exit bye
[root@host51 mongodb]#mongod shutdown -f /usr/local/mongodb/etc/mongodb.conf
把启动和停止服务命令名定义别名 [root@host51 mongodb]#alias startmgo='mongod -f /usr/local/mongodb/etc/mongodb.conf' [root@host51 mongodb]#alias stopmgo='mongod -f /usr/local/mongodb/etc/mongodb.conf --shutdown'
修改服务使用的ip地址和端口号 [root@host51 mongodb]#vim /usr/local/mongodb/etc/mongodb.conf bind_ip=192.168.4.51 port=27051 :wq
[root@host51 mongodb]#stopmgo [root@host51 mongodb]#startmgo
[root@host51 mongodb]# netstat -utnlp | grep mongod tcp 0 0 192.168.4.51:27051 0.0.0.0:* LISTEN
11337/mongod
连接服务 [root@host51 mongodb]# mongo --host 192.168.4.51 --port 27051