验证 mongos 服务器是否连接到配置服务器

Ale*_*ura 8 mongodb sharding

我一直在为分片副本集编写备份脚本,它几乎完成了。除了在一切都说完之后,我似乎无法让它成功启动平衡器备份。

这是我试图用来启动平衡器备份的命令;请记住,这是通过 SSH 在实际的 mongos 服务器上运行的。

sudo -s
mongo -u username -p password --authenticationDatabase db
use config
sh.setBalancerState(true)
exit
exit
exit
Run Code Online (Sandbox Code Playgroud)

每当脚本遇到startBalancer运行上述代码的函数时,我都会收到以下错误。

SyncClusterConnection::udpate prepare failed:  mongo-conf-0.foo.bar.com:27019:10276 
DBClientBase::findN: transport error: mongo-conf-0.foo.bar.com:27019 
ns: admin.$cmd query: { resetError: 1 }
Run Code Online (Sandbox Code Playgroud)

我试过检查mongoshell 进程的退出状态,使用类似

sudo -s
mongo -u username -p password --authenticationDatabase db
use config
sh.setBalancerState(true)
exit
exit
exit
Run Code Online (Sandbox Code Playgroud)

但不管 mongo-shell 中实际发生了什么,退出代码似乎总是 0。

关于如何在尝试重新启用平衡器之前验证 mongos 进程是否实际连接到所有三个配置的任何想法?我认为问题在于 mongos 服务器在 mongod 进程有机会完成启动之前尝试连接到配置服务器(分片副本集的备份过程的一部分正在关闭其中一个配置服务器

Ada*_*m C 0

您是否尝试过使用sh.startBalancer()助手

它不是直接更新,而是需要一个超时参数(等待平衡开始的时间)以及睡眠间隔(等待之间睡眠的时间)。以下是 shell 中的代码作为解释:

mongos> sh.startBalancer
function ( timeout, interval ) {
    sh.setBalancerState( true )
    sh.waitForBalancer( true, timeout, interval )
}
Run Code Online (Sandbox Code Playgroud)

因此,如果您愿意,您甚至可以将其分解并使用waitForBalancer助手。作为参考,以下是stopBalancer当我尝试通过配置服务器关闭来停止它时出错的等效命令:

mongos> sh.stopBalancer(2000, 100)
Waiting for active hosts...
Waiting for active host adamc-mbp.local:30999 to recognize new settings... (ping : Tue Dec 31 2013 19:51:32 GMT+0000 (GMT))
Waiting for the balancer lock...
Waiting again for active hosts after balancer is off...
Tue Dec 31 19:51:39.243 error: {
    "$err" : "error creating initial database config information :: caused by :: SyncClusterConnection::udpate prepare failed:  localhost:29000:9001 socket exception [FAILED_STATE] server [localhost:29000] ",
    "code" : 8005
} at src/mongo/shell/query.js:128
Run Code Online (Sandbox Code Playgroud)