5

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

4

1 回答 1

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

请注意,您必须将 mongod/mongos 命令中的“localhost”替换为您计算机的主机名,否则您将无法配置分片。

另请参阅此:

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

如果您需要命令行来完成这项工作,这里有一个:

mongo 管理员 --port 端口号 --eval "db.shutdownServer()"

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

于 2015-02-27T04:59:00.020 回答