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

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.有关此情况的更多信息,请参阅副本集选择

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. force选项将新配置强制到构件上。Use this procedure only to recover from catastrophic interruptions. 仅使用此过程从灾难性中断中恢复。Do not use force every time you reconfigure. 每次重新配置时不要使用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. 然后将配置传播到members数组中列出的所有幸存成员。The replica set then elects a new primary.然后,副本集选择一个新的主副本。

    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.如果故障或分区只是暂时的,请尽快关闭或停用被移除的成员。
←  Configure Replica Set Tag SetsManage Chained Replication →