On this page本页内容
To reconfigure a replica set when a majority of members are available, use the 要在大多数成员可用时重新配置副本集,请按照副本集重新配置过程中的示例,在当前主副本上使用rs.reconfig()
operation on the current primary, following the example in the Replica Set Reconfiguration Procedure.rs.reconfig()
操作。
This document provides steps for re-configuring a replica set when only a minority of members are accessible.本文档提供了在只有少数成员可访问时重新配置副本集的步骤。
You may need to use the procedure, for example, in a geographically distributed replica set, where no local group of members can reach a majority. 例如,您可能需要在地理位置分散的副本集中使用该过程,因为本地成员组无法达到多数。See Replica Set Elections for more information on this situation.有关此情况的更多信息,请参阅副本集选择。
This procedure lets you recover while a majority of replica set members are down or unreachable. 此过程允许您在大多数副本集成员关闭或无法访问时进行恢复。You connect to any surviving member and use the 您可以连接到任何幸存的成员,并对force
option to the rs.reconfig()
method.rs.reconfig()
方法使用force
选项。
The force
option forces a new configuration onto the member. force
选项将新配置强制到构件上。Use this procedure only to recover from catastrophic interruptions. 仅使用此过程从灾难性中断中恢复。Do not use 每次重新配置时不要使用force
every time you reconfigure. force
。Also, do not use the 此外,不要在任何自动脚本中使用force
option in any automatic scripts and do not use force
when there is still a primary.force
选项,也不要在仍然有primary使用force
。
To force reconfiguration:要强制重新配置:
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. members
数组中删除副本集的向下和无法访问的成员。Consider the following example, which uses the 考虑以下示例,该示例使用上一步骤中创建的cfg
variable created in the previous step:cfg
变量:
cfg.members = [cfg.members[0] , cfg.members[4] , cfg.members[7]]
On the same member, reconfigure the set by using the 在同一成员上,使用rs.reconfig()
command with the force
option set to true
:rs.reconfig()
命令重新配置集合,并将force
选项设置为true
:
rs.reconfig(cfg, {force : true})
This operation forces the secondary to use the new configuration. 此操作强制辅助设备使用新配置。The configuration is then propagated to all the surviving members listed in the 然后将配置传播到members
array. members
数组中列出的所有幸存成员。The replica set then elects a new primary.然后,副本集选择一个新的主副本。
When you use 当您使用force : true
, the version number in the replica set configuration increases significantly, by tens or hundreds of thousands. force:true
时,副本集配置中的版本号会显著增加,增加数万或数十万。This is normal and designed to prevent set version collisions if you accidentally force re-configurations on both sides of a network partition and then the network partitioning ends.这是正常的,旨在防止设置版本冲突,如果您意外地在网络分区的两侧强制重新配置,然后网络分区结束。