Docs HomeMongoDB Manual

Reconfigure a Replica Set with Unavailable Members使用不可用的成员重新配置副本集

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.要在大多数成员可用时重新配置副本集,请按照副本集重新配置过程中的示例,在当前primary上使用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.有关此情况的详细信息,请参阅副本集选择

Reconfigure by Forcing the Reconfiguration通过强制重新配置进行重新配置

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. Use this procedure only to recover from catastrophic interruptions. Do not use force every time you reconfigure. force选项可将新配置强制到成员上。使用此过程仅用于从灾难性中断中恢复。不要每次重新配置时都使用forceAlso, 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:要强制重新配置:

  1. Back up a surviving member.备份幸存的成员。
  2. Connect to a surviving member and save the current configuration. 连接到幸存的成员并保存当前配置。Consider the following example commands for saving the configuration:请考虑以下用于保存配置的示例命令:

    cfg = rs.conf()

    printjson(cfg)
  3. 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]]
  4. 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. The replica set then elects a new primary.然后将配置传播到members数组中列出的所有幸存成员。复制副本集然后选择一个新的主副本。

    Note

    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.这是正常的,旨在防止在网络分区两侧意外强制重新配置,然后网络分区结束时发生设置版本冲突。

  5. If the failure or partition was only temporary, shut down or decommission the removed members as soon as possible.如果故障或分区只是暂时的,请尽快关闭或停用已删除的成员。