关闭mongos进行升级

时间:2013-04-08 16:43:08

标签: mongodb

我正在升级mongodb分片群集,并且是更换mongos进程的第一步。我可以直接杀死这个过程,还是在更换它之前有更安全的方法来关闭它?

1 个答案:

答案 0 :(得分:2)

这是答案。但可能是你被误解了。您无法从命令行关闭mongos,但您必须登录到shell。以下是我自己尝试的结果:

$ mongo --port 27077 (please replace with your own port on mongos instance)

**mongos**> db.shutdownServer({timeoutSecs:30})
shutdown command only works with the admin database; try 'use admin'
mongos> use admin
switched to db admin
mongos> db.shutdownServer({timeoutSecs:30})
2015-02-27T12:53:54.408+0800 DBClientCursor::init call() failed
**server should be down...**
2015-02-27T12:53:54.410+0800 trying reconnect to 127.0.0.1:27077 (127.0.0.1) failed
2015-02-27T12:53:54.410+0800 warning: Failed to connect to 127.0.0.1:27077, reason: errno:111 Connection refused
2015-02-27T12:53:54.410+0800 reconnect 127.0.0.1:27077 (127.0.0.1) failed failed couldn't connect to server 127.0.0.1:27077 (127.0.0.1), connection attempt failed
2015-02-27T12:53:54.413+0800 trying reconnect to 127.0.0.1:27077 (127.0.0.1) failed
2015-02-27T12:53:54.413+0800 warning: Failed to connect to 127.0.0.1:27077, reason: errno:111 Connection refused
2015-02-27T12:53:54.413+0800 reconnect 127.0.0.1:27077 (127.0.0.1) failed failed couldn't connect to server 127.0.0.1:27077 (127.0.0.1), connection attempt failed
> 

尝试运行" top"或" htop"显示计算机上运行的所有进程。你会看到" mongos"过程已经过去了。阅读日志文件。这是我日志的最后两行:

2015-02-27T12:53:54.406+0800 [conn1] terminating, shutdown command received
2015-02-27T12:53:54.406+0800 [conn1] dbexit: shutdown called rc:0 shutdown called

这是我的测试脚本的链接:

https://github.com/babycaseny/QuickStart/blob/master/StartShard.sh

请注意,您必须更换" localhost"在使用计算机主机名的mongod / mongos命令中,或者您将无法配置分片。

另见这一篇:

https://groups.google.com/forum/#!topic/mongodb-user/TQLlRI6HG1M

如果您需要命令行来完成工作,请参阅:

mongo admin --port portnumber --eval" db.shutdownServer()"

请注意,您必须在localhost中运行该命令。