系统环境:CentOS6.5
软件:mongodb2.8
原来是想到现在的数据进行添加副本集,方便读写的,没想到悲剧了,现在连原来的主数据都变成了从的数据库,怎么也换不过去。
尝试了两个解决办法:
1 . 登录的原的主mongodb ,用rs.remove()的办法把后来添加的副本集从member里移掉,失败了。
真的悲剧了,怎么都remove不掉,因为原来的master已经变成了slave,不能remove其它成员
2 . 更改config,修改member 0 的优先级,抢占master。
执行也是失败,因为当前不是master 。
无奈,只能另找其它办法,因为对mongo数据的并不太熟悉。
后来看了一下网上的文章:https://segmentfault.com/q/1010000000532867 也是关于这个问题的。
大概想到了解决方法:关掉此mongo的服务,将此实例中的local配置目录移除,再重新启动,再用rs.initiate(cfg)的方法配置为master ,搞掂。原来的数据还在哈哈
step 1 . 关闭数据库:./bin/mongod --shutdown --dbpath /data/mongo/datacore
step 2 . 删除或移动原来的副本集数据中的local : #mv /data/mongo/datacore /tmp
这里不删除,怕是有一些重要的配置在里面哈
step 3 . 启动mongo , 重做配置
[root@xxxxx mongodb]#/usr/local/mongodb/bin/mongod --directoryperdb --rest -replSet msbuset1 --dbpath=/data/mongo/datacore --port 27018 --fork --logpath /data/mongo/logs/datacorefile.log --logappend --maxConns 1600
[root@xxxxx mongodb]# ./bin/mongo --port 27017
MongoDB shell version: 2.4.9
connecting to: 127.0.0.1:27017/test
>
> show dbs;
eventDev 0.203125GB
local 0.078125GB
message 0.203125GB
ossDev 0.203125GB
p2f 0.203125GB
snsDev 0.203125GB
snsUser 0.203125GB
test 0.203125GB
todo 0.203125GB
> rs.stats()
Thu Mar 31 13:33:21.757 TypeError: Object function () { return "try rs.help()"; } has no method 'stats'
> rs.status()
{
"startupStatus" : 3,
"info" : "run rs.initiate(...) if not yet done for the set",
"ok" : 0,
"errmsg" : "can't get local.system.replset config from self or any seed (EMPTYCONFIG)"
}
> cfg={_id:'msbuset0',members:[{_id:0,host:'${mongo_add_master}:27017',priority:10}]}
{
"_id" : "msbuset0",
"members" : [
{
"_id" : 0,
"host" : "${mongo_add_master}:27017",
"priority" : 10
}
]
}
> rs.initiate(cfg)
{
"ok" : 0,
"errmsg" : "couldn't initiate : can't find self in the replset config"
}
> cfg={_id:'msbuset0',members:[{_id:0,host:'192.168.22.198:27017',priority:10}]}
{
"_id" : "msbuset0",
"members" : [
{
"_id" : 0,
"host" : "192.168.22.198:27017",
"priority" : 10
}
]
}
> rs.initiate(cfg)
{
"info" : "Config now saved locally. Should come online in about a minute.",
"ok" : 1
}
>
>
>
>
>
>
>
>
>
> rs.status()
{
"set" : "msbuset0",
"date" : ISODate("2016-03-31T05:36:34Z"),
"myState" : 1,
"members" : [
{
"_id" : 0,
"name" : "192.168.22.198:27017",
"health" : 1,
"state" : 1,
"stateStr" : "PRIMARY",
"uptime" : 234,
"optime" : Timestamp(1459402537, 5),
"optimeDate" : ISODate("2016-03-31T05:35:37Z"),
"self" : true
}
],
"ok" : 1
}
msbuset0:PRIMARY>
哈哈,终于成功了。
这也许是一个比较笨的方法,因为现在对mongodb并不熟悉。
如果大家有好的办法,也可以说一下哈
转载于:https://blog.51cto.com/plong/1758830