mongodb 如何强制 mongod 成为副本集中的主节点?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/25585226/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to force a mongod to become primary in a replica set?
提问by Towhid
1) I have 3 mongodbs running in a replica set
1)我有 3 个 mongodbs 在副本集中运行
mongod --fork --logpath a.log --smallfiles --oplogSize 50 --port 27001 --dbpath data/z1 --replSet z
mongod --fork --logpath b.log --smallfiles --oplogSize 50 --port 27002 --dbpath data/z2 --replSet z
mongod --fork --logpath c.log --smallfiles --oplogSize 50 --port 27003 --dbpath data/z3 --replSet z
2) Now 27001 and 27002 are down.
2)现在27001和27002下跌。
What do I need to do to make 27003 primary without restarting 27001 and 27002?
我需要做什么才能在不重新启动 27001 和 27002 的情况下使 27003 成为主要的?
采纳答案by Sammaye
You have to reconfig the replica set: http://docs.mongodb.org/manual/tutorial/reconfigure-replica-set-with-unavailable-members/
您必须重新配置副本集:http: //docs.mongodb.org/manual/tutorial/reconfigure-replica-set-with-unavailable-members/
Namely you have to actually go onto that member and run a rs.reconfig to remove those two dead members from the set since you have a majority of the members offline.
也就是说,您必须实际访问该成员并运行 rs.reconfig 以从集合中删除这两个死成员,因为您有大多数成员离线。
回答by Markus W Mahlberg
Here is how you can do it.
这是您如何做到的。
The really easy way
真正简单的方法
Restart the other two instances after deleting the contents of their dbpath
.
删除它们的内容后重新启动其他两个实例dbpath
。
The easy, but insecure way
简单但不安全的方式
Assuming you can not get the other nodes back online (which reminds me a bit of a homework for M102)
假设你不能让其他节点重新上线(这让我想起了 M102 的作业)
replset:SECONDARY> oldConf = rs.conf()
[...]
replset:SECONDARY> conf = {
...
... _id:oldConf._id,
... version: oldConf.version + 1,
... members: [ oldConf.members[2] ]}
[...]
replset:SECONDARY> rs.reconfig(conf,{force:true})
Note: Instead of putting 2 at oldConf.members[2]
, you need to put in the position of the instance running on port 27013 in oldConfig.members
, starting from 0. After you sent the rs.reconfig
command, it may take a few seconds for the last node to come up as primary.
注意:不是将 2 放在oldConf.members[2]
,而是需要将在端口 27013 上运行的实例的位置放在 中oldConfig.members
,从 0 开始。 发送rs.reconfig
命令后,最后一个节点可能需要几秒钟才能作为主节点出现。
The sensible way
明智的方式
Get up two other nodes with the according --replSet
parameter and use the procedure described above to add them by adding them to the members array of conf
.
--replSet
使用相应的参数设置另外两个节点,并使用上述过程通过将它们添加到 的成员数组来添加它们conf
。