mongodb 如果副本集中的节点数量最多,如何将辅助节点转换为主节点?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16331276/
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 Convert secondary Node to primary if maximum of node down in a replica set?
提问by Rajnish
I am using mongodb with replica set ,which have 3 nodes lets their ip's are 192.168.1.100 , 192.168.1.101,192.168.1.102 .
我正在使用带有副本集的 mongodb,其中有 3 个节点,它们的 ip 是 192.168.1.100 , 192.168.1.101,192.168.1.102 。
In MY current setup 192.168.1.100 is Primary and others are Secondary .I have set priority for 192.168.1.100 and 192.168.1.101 is 1 and for 192.168.1.102 is 0 , now After some time my 192.168.1.100 and 192.168.1.101 both node are down .
在我当前的设置中 192.168.1.100 是主要的,其他人是次要的。我已经将 192.168.1.100 和 192.168.1.101 的优先级设置为 1 ,而 192.168.1.102 的优先级为 0 ,现在经过一段时间后,我的 192.191.106 和 192.101.106 节点都设置了都下来了。
I want to force 192.168.1.102 to become primary so that My application will live . Is their is any way to Forcefully convert 192.168.1.102 node to become primary NODE.
我想强制 192.168.1.102 成为主要的,这样我的应用程序才能存活。他们有什么方法可以强制将 192.168.1.102 节点转换为主节点。
采纳答案by Rajnish
Solutions to overcome from this situation is ,If there is only one node remains in replica set and that node is secondary(Having Priority 0) then first shutdown the node extract node from replica set (by comment repliSet line from mongod.conf or start mongo go to mongo command line use local modify records from system.replset and delete record) , then start node as a standalone mongodb :)
克服这种情况的解决方案是,如果副本集中只有一个节点并且该节点是辅助节点(具有优先级 0),则首先关闭副本集中的节点提取节点(通过 mongod.conf 中的注释 repliSet 行或启动 mongo转到 mongo 命令行使用 system.replset 中的本地修改记录并删除记录),然后将节点作为独立的 mongodb 启动 :)
回答by Zafar Malik
You can achieve it without mongod service restart by below steps-
您可以通过以下步骤在不重启 mongod 服务的情况下实现它-
connect to active member suppose it is running on localhost on 27017 port:
连接到活动成员,假设它在 localhost 上的 27017 端口上运行:
mongo --port 27017
Get your member ids from here-
从这里获取您的会员 ID-
> use admin
> rs.status()
Suppose your active member id is 1. then reconfigure your replication as per below steps-
假设您的活动成员 ID 为 1。然后按照以下步骤重新配置您的复制-
> cfg = rs.conf()
> cfg.members = [cfg.members[1]]
> rs.reconfig(cfg, {force : true})
It will make your remiaining active member to primary and available for application and writes.
它将使您的活跃会员成为主要会员并可供申请和写入。
回答by Linda Qin
You can follow the steps hereto reconfigure replica set when a majority of members are not accessible.
当大多数成员无法访问时,您可以按照此处的步骤重新配置副本集。
As you have only one node left in the replica set, your data will not be replicated. You'd better add these two nodes back once they are alive.
由于副本集中只剩下一个节点,因此不会复制您的数据。最好在这两个节点活着后将它们添加回来。
回答by Vaseem007
I sloved my issue by following as below:
我通过以下方式解决了我的问题:
Connect to a surviving member and save the current configuration. Consider the following example commands for saving the configuration:
连接到幸存的成员并保存当前配置。考虑以下用于保存配置的示例命令:
cfg = rs.conf()
printjson(cfg)
On the same member, remove the down and unreachable members of the replica set from the members array by setting the array equal to the surviving members alone.
在同一个成员上,通过将数组设置为与单独幸存的成员相等,从成员数组中删除副本集的宕机和无法访问的成员。
let's only the single member is remained
让我们只剩下一个成员
# Don't c/p if you have more than 1 node in your replica set
cfg.members = [cfg.members[0]]
member[0] is the one that is in frist in array what get in rs.conf() reconfigure the set with the force option set to true:
member[0] 是数组中的第一个,在 rs.conf() 中获得的内容重新配置该集合,并将 force 选项设置为 true:
rs.reconfig(cfg, {force : true})
Now you can see that surviving member is now PRIMARY. Source: https://docs.mongodb.com/v3.4/tutorial/reconfigure-replica-set-with-unavailable-members/
现在您可以看到幸存的成员现在是 PRIMARY。来源:https: //docs.mongodb.com/v3.4/tutorial/reconfigure-replica-set-with-unavailable-members/
回答by Sammaye
Not without manual intervention in this case. You will also suffer another problem. The majority of the set will be offline, this means that even without a priority of 0 your remaining replica member would not become primary.
在这种情况下,并非没有人工干预。你还会遇到另一个问题。该集合的大部分将处于离线状态,这意味着即使没有优先级 0,您剩余的副本成员也不会成为主要成员。
Instead what you must do is either get the majority of the set back up or you must run a rs.reconfig()
removing the two dead members of your set.
相反,您必须做的是要么恢复大部分集合,要么必须运行rs.reconfig()
删除集合中的两个死成员。
You cna find examples etc here: http://docs.mongodb.org/manual/tutorial/reconfigure-replica-set-with-unavailable-members/
您可以在这里找到示例等:http: //docs.mongodb.org/manual/tutorial/reconfigure-replica-set-with-unavailable-members/