分类: MongoDB

MongoDB分片启动失败解决方法

MongoDB机器未能正常关机,机器掉电重启等各种情况,都可能引起mongodb数据文件异常,然后下次启动的时候,会报错大概如下

517322 2018-01-03T22:20:45.939+0800 I NETWORK  [Balancer] scoped connection to 10.249.3.12:20000,10.249.3.11:20000,10.249.3.11:20003 not being returned to the pool
517323 2018-01-03T22:20:45.939+0800 I SHARDING [Balancer] caught exception while doing balance: ReplicaSetMonitor no master found for set: shard1
517324 2018-01-03T22:20:46.540+0800 I NETWORK  [LockPinger] SyncClusterConnection connecting to [10.249.3.12:20000]
517325 2018-01-03T22:20:46.541+0800 I NETWORK  [LockPinger] SyncClusterConnection connecting to [10.249.3.11:20000]
517326 2018-01-03T22:20:46.541+0800 I NETWORK  [LockPinger] SyncClusterConnection connecting to [10.249.3.11:20003]
517327 2018-01-03T22:20:49.748+0800 W SHARDING config servers 10.249.3.12:20000 and 10.249.3.11:20000 differ
517328 2018-01-03T22:20:49.749+0800 W SHARDING config servers 10.249.3.12:20000 and 10.249.3.11:20000 differ
517329 2018-01-03T22:20:49.751+0800 W SHARDING config servers 10.249.3.12:20000 and 10.249.3.11:20000 differ
517330 2018-01-03T22:20:49.752+0800 W SHARDING config servers 10.249.3.12:20000 and 10.249.3.11:20000 differ

重点在differ这里,两个分片不一致,导致不能启动,解决方法如下:
分别安全关闭10.249.3.11和12的MongoDB

/usr/local/mongodb/bin/mongo -host 127.0.0.1 -port 20000
> use admin; 
> db.shutdownServer();

进入到3.11机器的对应数据目录,将文件整个打包,
进入到3.12机器的数据目录/data/mongodb/config20001,删除所有文件,记得备份,
最后scp 11.zip 10.249.3.12:/data/mongodb/config20001 ,然后解压,最后启动mongodb即可;

相关文章

此处评论已关闭