![]()
4.2 停止數(shù)據(jù)庫(kù) MongoDB提供的停止數(shù)據(jù)庫(kù)命令也非常豐富,如果Control-C、發(fā)送shutdownServer()指令及發(fā)送Unix系統(tǒng)中斷信號(hào)等 4.2.1 Control-C 如果處理連接狀態(tài),那么直接可以通過(guò)Control-C的方式去停止MongoDB實(shí)例,具體如下: [root@localhost ~]# /Apps/mongo/bin/mongo --port 28013 MongoDB shell version: 1.8.1 connecting to: 127.0.0.1:28013/test > use test switched to db test > ^C[root@localhost ~]# |
4.2.2 shutdownServer()指令 如果處理連接狀態(tài),那么直接可以通過(guò)在admin庫(kù)中發(fā)送db.shutdownServer()指令去停止MongoDB實(shí)例,具體如下: [root@localhost ~]# /Apps/mongo/bin/mongo --port 28013 MongoDB shell version: 1.8.1 connecting to: 127.0.0.1:28013/test > use admin switched to db admin > db.shutdownServer() Thu May 31 23:22:00 DBClientCursor::init call() failed Thu May 31 23:22:00 query failed : admin.$cmd { shutdown: 1.0 } to: 127.0.0.1:28013 server should be down... Thu May 31 23:22:00 trying reconnect to 127.0.0.1:28013 Thu May 31 23:22:00 reconnect 127.0.0.1:28013 failed couldn't connect to server 127.0.0.1:28013 Thu May 31 23:22:00 Error: error doing query: unknown shell/collection.js:150 > |
4.2.3 Unix系統(tǒng)指令 在找到實(shí)例的進(jìn)程后,可能通過(guò)發(fā)送kill -2 PID或kill -15 PID來(lái)停止進(jìn)程 [root@localhost ~]# ps aux|grep mongod root 19269 0.3 1.3 76008 3108 Sl 23:24 0:00 /Apps/mongo/bin/mongod --fork --port 28013 [root@localhost ~]# kill -2 19269 |
注意: 不要用kill -9 PID來(lái)殺死MongoDB進(jìn)程,這樣可以會(huì)導(dǎo)致MongoDB的數(shù)據(jù)損壞 |
-------------------------------------------------------------------
《MongoDB管理與開(kāi)發(fā)精要》、《Redis實(shí)戰(zhàn)》作者
ChinaUnix.net專家 http://cdhongwan.blog.chinaunix.net
@CD紅丸 http://weibo.com/u/2446082491
|