cd红丸 发表于 2012-06-14 20:16

[原创] MongoDB管理与开发精要《红丸出品》4.2 停止数据库


http://blog.chinaunix.net/attachment/201205/26/26785103_1338009683Kvjx.jpg
4.2 停止数据库 MongoDB提供的停止数据库命令也非常丰富,如果Control-C、发送shutdownServer()指令及发送Unix系统中断信号等4.2.1 Control-C 如果处理连接状态,那么直接可以通过Control-C的方式去停止MongoDB实例,具体如下:
#/Apps/mongo/bin/mongo --port 28013MongoDB shell version: 1.8.1connecting to: 127.0.0.1:28013/test> use testswitched to db test> ^C#

4.2.2 shutdownServer()指令 如果处理连接状态,那么直接可以通过在admin库中发送db.shutdownServer()指令去停止MongoDB实例,具体如下:
#/Apps/mongo/bin/mongo --port 28013MongoDB shell version: 1.8.1connecting to: 127.0.0.1:28013/test> use adminswitched to db admin> db.shutdownServer()Thu May 31 23:22:00 DBClientCursor::init call() failedThu May 31 23:22:00 query failed : admin.$cmd { shutdown: 1.0 } to: 127.0.0.1:28013server should be down...Thu May 31 23:22:00 trying reconnect to 127.0.0.1:28013Thu May 31 23:22:00 reconnect 127.0.0.1:28013 failed couldn't connect to server 127.0.0.1:28013Thu May 31 23:22:00 Error: error doing query: unknown shell/collection.js:150>

4.2.3 Unix系统指令 在找到实例的进程后,可能通过发送kill -2 PID或kill -15 PID来停止进程
# ps aux|grep mongodroot 192690.31.3760083108 Sl   23:24   0:00 /Apps/mongo/bin/mongod --fork --port 28013# kill -2 19269


注意:不要用kill -9 PID来杀死MongoDB进程,这样可以会导致MongoDB的数据损坏

-------------------------------------------------------------------
《MongoDB管理与开发精要》、《Redis实战》作者
ChinaUnix.net专家 http://cdhongwan.blog.chinaunix.net
@CD红丸         http://weibo.com/u/2446082491

页: [1]
查看完整版本: [原创] MongoDB管理与开发精要《红丸出品》4.2 停止数据库