问题描述
我们有一个mongoDB副本集,其中有3个节点;
We have a mongoDB replica set which has 3 nodes;
- 主要
- 中学
- 仲裁者
某种程度上,我们的副本集以1& 2个都被设置为次要成员.我不确定这是怎么发生的(我们进行了服务器迁移,其中一个节点在其上运行,但是只有一个).
Somehow our replica set has ended up with 1 & 2 both being set as secondary members. I'm not sure how this has happened (we have had a server migration which one of the nodes runs on, but only one).
无论如何,我一直在按照指南此处
Anyway, I've been trying to re-elect a new primary for the replica set following the guide here
我不能只使用
rs.reconfig(cfg)
因为它只有在指向主要对象(我没有)的情况下才起作用.
as it will only work if directed at the primary (which I don't have).
使用力参数
rs.reconfig(cfg, { force: true})
似乎可以使用,但是当我重新查询副本集的状态时,两个服务器仍仅显示为辅助".
would appear to work but then when I requery the status of the replica set, both servers are still only showing as Secondary.
为什么强制重新配置不起作用?目前,无论我如何尝试,数据库都被锁定.
Why hasn't the force reconfig worked? Currently the database is locked out whatever I try.
推荐答案
1.将所有节点转换为独立节点.
停止mongod守护进程并编辑/etc/mongod.conf
以评论replSet
选项.
Stop mongod deamon and edit /etc/mongod.conf
to comment replSet
option.
启动mongod守护进程.
Start mongod deamon.
2.使用mongodump
备份所有节点的数据.
2.Use mongodump
to backup data for all nodes.
mongo文档参考:
Reference from mongo docs:
https://docs.mongodb.com/manual/reference/program/mongodump/
3.登录到每个节点,并删除local
数据库.
3.Log into each node, and drop local
database.
这样做将删除节点上的副本集配置.
Doing this will delete replica set config on the node.
或者您也可以删除本地db中集合system.replset
中的一条记录,如下所示:
Or you can just delete a record in collection system.replset
in local db, like it said here:
https://stackoverflow.com/a/31745150/4242454
4.使用replSet
选项启动所有节点.
4.Start all nodes with replSet
option.
5.在上一个数据节点(不是仲裁器)上,初始化一个新的副本集.
6.最后,用rs.reconfig
重新配置副本集.
6.Finally, reconfig replica set with rs.reconfig
.
这篇关于MongoDB副本集未设置主副本,需要强制使用新的主副本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!