作者:zhanhailiang 日期:2014-11-07
1. 安裝mongodb:
[root@~/wade/nodejs/nodeclub]# yum search mongodb [root@~/wade/nodejs/nodeclub]# yum install mongodb.x86_64 mongodb-server.x86_64 libmongodb.x86_64 libmongodb-devel.x86_64
2. 採用配置檔案+後臺執行模式啟動mongodb服務:
[root@/usr/local/mongodb]# ls conf data log [root@/usr/local/mongodb/conf]# cat mongodb_27017.conf fork = true bind_ip = 127.0.0.1 port = 27017 dbpath = /usr/local/mongodb/data/ logpath = /usr/local/mongodb/log/mongodb_27017.log logappend = true journal = true [root@/usr/local/mongodb/conf]# mongod -f /usr/local/mongodb/conf/mongodb_27017.conf about to fork child process, waiting until server is ready for connections. forked process: 21732 all output going to: /usr/local/mongodb/log/mongodb_27017.log child process started successfully, parent exiting [root@/usr/local/mongodb/conf]# ps -ef|grep mongodb root 21732 1 0 23:12 ? 00:00:00 mongod -f /usr/local/mongodb/conf/mongodb_27017.conf root 21750 21441 0 23:12 pts/1 00:00:00 grep mongodb
當中:
-
fork:表示是否以後臺程式模式啟動。
-
bind_ip:MongoDB程式繫結的監聽IP,默覺得 localhost(127.0.0.1)
-
port:MongoDB 服務監聽的TCP埠,默覺得 27017
-
dbpath:資料資料夾
-
logpath:日誌資料夾
-
logappend:日誌追加
-
journal: 是否開啟預寫日誌
3. 使用clientmongo登入mongodb,測試mongodb服務是否正常執行:
[root@/usr/local/mongodb/conf]# mongo MongoDB shell version: 2.4.6 connecting to: test > version() 2.4.6
4. 停止mongodb服務:
能夠使用client登入停止mongodb服務:
[root@/usr/local/mongodb/conf]# mongo MongoDB shell version: 2.4.6 connecting to: test > use admin; switched to db admin > db.shutdownServer(); Fri Nov 7 23:46:54.710 DBClientCursor::init call() failed server should be down... Fri Nov 7 23:46:54.712 trying reconnect to 127.0.0.1:27017 Fri Nov 7 23:46:54.712 reconnect 127.0.0.1:27017 failed couldn't connect to server 127.0.0.1:27017
也能夠使用 mongod 命令關閉:
[root@/usr/local/mongodb/conf]# mongod --shutdown -f /usr/local/mongodb/conf/mongodb_27017.conf killing process with pid: 23099
推薦閱讀: