Docs HomeMongoDB Manual

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

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. Both procedures are operationally equivalent:如果副本集中有一个secondary,它不再需要保存数据,但需要保留在该集中以确保该集可以选择primary,则可以使用本教程中的任一过程将该辅助副本转换为仲裁器。这两个程序在操作上是等效的:

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将Secondary转换为Arbiter并重用端口号

  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中连接到当前primary时执行此操作:

    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()方法,验证副本集是否不再包括secondary:

    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. You can reuse the previous name. 创建一个新的空数据目录,以便在重新启动mongod实例时指向。您可以重复使用以前的名称。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 you bind your instance to a publicly-accessible IP address, you must secure 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()方法将secondary转换为仲裁器:

    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 you bind your instance to a publicly-accessible IP address, you must secure 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.您可以删除数据。