Convert a Secondary to an Arbiter将辅助转换为仲裁器

On this page本页内容

If you have a secondary in a replica set that no longer needs to hold data but that needs to remain in the set to ensure that the set can elect a primary, you may convert the secondary to an arbiter using either procedure in this tutorial. 如果副本集中有一个secondary,它不再需要保存数据,但需要保留在该集中以确保该集可以选择primary,则可以使用本教程中的任一过程将辅助副本转换为仲裁器Both procedures are operationally equivalent:这两种程序在操作上是等效的:

Note注意

For the following MongoDB versions, pv1 increases the likelihood of w:1 rollbacks compared to pv0(no longer supported in MongoDB 4.0+) for replica sets with arbiters:对于以下MongoDB版本,对于具有仲裁器的副本集,与pv0(MongoDB 4.0+不再支持)相比,pv1增加了w:1回滚的可能性:

  • MongoDB 3.4.1
  • MongoDB 3.4.0
  • MongoDB 3.2.11 or earlier

See Replica Set Protocol Version.请参阅副本集协议版本

Convert Secondary to Arbiter and Reuse the Port Number将辅助转换为仲裁器并重用端口号

  1. If your application is connecting directly to the secondary, modify the application so that MongoDB queries don't reach the secondary.如果应用程序直接连接到辅助服务器,请修改应用程序,使MongoDB查询不会到达辅助服务器。
  2. Shut down the secondary.关闭辅助设备。
  3. Remove the secondary from the replica set by calling the rs.remove() method. 通过调用rs.remove()方法从副本集中删除secondaryPerform this operation while connected to the current primary in mongosh:连接到mongosh中的当前主电源时执行此操作:

    rs.remove("<hostname><:port>")
  4. Verify that the replica set no longer includes the secondary by calling the rs.conf() method in mongosh:通过调用mongosh中的rs.conf()方法,验证副本集不再包含辅助副本:

    rs.conf()
  5. Move the secondary's data directory to an archive folder. For example:将辅助设备的数据目录移动到存档文件夹。例如:

    mv /data/db /data/db-old
    Note注意
    Optional

    You may remove the data instead.您可以改为删除数据。

  6. Create a new, empty data directory to point to when restarting the mongod instance. 创建一个新的空数据目录,以在重新启动mongod实例时指向该目录。You can reuse the previous name. 您可以重复使用以前的名称。For example:例如:

    mkdir /data/db
  7. Restart the mongod instance for the secondary, specifying the port number, the empty data directory, and the replica set. 重新启动次服务器的mongod实例,指定端口号、空数据目录和副本集。You can use the same port number you used before. Issue a command similar to the following:您可以使用以前使用的相同端口号。发出类似于以下内容的命令:

    Warning警告

    Before binding to a non-localhost (e.g. publicly accessible) IP address, ensure you have secured your cluster from unauthorized access. 在绑定到非本地主机(例如,可公开访问的)IP地址之前,请确保已保护集群免受未经授权的访问。For a complete list of security recommendations, see Security Checklist. 有关安全建议的完整列表,请参阅安全检查表At minimum, consider enabling authentication and hardening network infrastructure.至少,考虑启用身份验证加强网络基础设施

    mongod --port 27021 --dbpath /data/db --replSet rs  --bind_ip localhost,<hostname(s)|ip address(es)>
  8. In mongosh convert the secondary to an arbiter using the rs.addArb() method:mongosh中,使用rs.addArb()方法将辅助设备转换为仲裁器:

    rs.addArb("<hostname><:port>")
  9. Verify the arbiter belongs to the replica set by calling the rs.conf() method in mongosh.通过调用mongosh中的rs.conf()方法验证仲裁器是否属于副本集。

    rs.conf()

    The arbiter member should include the following:仲裁员成员应包括以下内容:

    "arbiterOnly" : true

Convert Secondary to Arbiter Running on a New Port Number将在新端口号上运行的辅助仲裁器转换为仲裁器

  1. If your application is connecting directly to the secondary or has a connection string referencing the secondary, modify the application so that MongoDB queries don't reach the secondary.如果您的应用程序直接连接到辅助服务器或具有引用辅助服务器的连接字符串,请修改应用程序,使MongoDB查询不会到达辅助服务器。
  2. Create a new, empty data directory to be used with the new port number. 创建一个新的空数据目录,用于新的端口号。For example:例如:

    mkdir /data/db-temp
  3. Start a new mongod instance on the new port number, specifying the new data directory and the existing replica set. 在新的端口号上启动一个新的mongod实例,指定新的数据目录和现有的副本集。Issue a command similar to the following:发出类似于以下内容的命令:

    Warning警告

    Before binding to a non-localhost (e.g. publicly accessible) IP address, ensure you have secured your cluster from unauthorized access. 在绑定到非本地主机(例如,可公开访问的)IP地址之前,请确保已保护集群免受未经授权的访问。For a complete list of security recommendations, see Security Checklist. 有关安全建议的完整列表,请参阅安全检查表At minimum, consider enabling authentication and hardening network infrastructure.至少,考虑启用身份验证加强网络基础设施

    mongod --port 27021 --dbpath /data/db-temp --replSet rs --bind_ip localhost,<hostname(s)|ip address(es)>
  4. In mongosh connected to the current primary, convert the new mongod instance to an arbiter using the rs.addArb() method:在连接到当前主节点的mongosh中,使用rs.addArb()方法将新的mongod实例转换为仲裁器:

    rs.addArb("<hostname><:port>")
  5. Verify the arbiter has been added to the replica set by calling the rs.conf() method in mongosh.通过调用mongosh中的rs.conf()方法,验证仲裁器是否已添加到副本集。

    rs.conf()

    The arbiter member should include the following:仲裁员成员应包括以下内容:

    "arbiterOnly" : true
  6. Shut down the secondary.关闭辅助设备。
  7. Remove the secondary from the replica set by calling the rs.remove() method in mongosh:通过调用mongosh中的rs.remove()方法从副本集中删除secondary

    rs.remove("<hostname><:port>")
  8. Verify that the replica set no longer includes the old secondary by calling the rs.conf() method in mongosh:通过调用mongosh中的rs.conf()方法,验证副本集不再包含旧的辅助副本:

    rs.conf()
  9. Move the secondary's data directory to an archive folder. 将辅助设备的数据目录移动到存档文件夹。For example:例如:

    mv /data/db /data/db-old
    Note注意
    Optional

    You may remove the data instead.

←  Configure Non-Voting Replica Set MemberReplica Set Maintenance Tutorials →