Convert a Secondary to an Arbiter将secondary转换为仲裁器
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. Both procedures are operationally equivalent:如果副本集中有一个secondary,它不再需要保存数据,但需要保留在该集中以确保该集可以选择primary,则可以使用本教程中的任一过程将该辅助副本转换为仲裁器。这两个程序在操作上是等效的:
You may operate the arbiter on the same port as the former secondary. In this procedure, you must shut down the secondary and remove its data before restarting and reconfiguring it as an arbiter.您可以在与前一个辅助端口相同的端口上操作仲裁器。在此过程中,必须先关闭辅助设备并删除其数据,然后再重新启动并将其配置为仲裁器。For this procedure, see Convert Secondary to Arbiter and Reuse the Port Number.有关此过程,请参阅将辅助端口转换为仲裁器并重新使用端口号。Run the arbiter on a new port. In this procedure, you can reconfigure the server as an arbiter before shutting down the instance running as a secondary.在新端口上运行仲裁器。在此过程中,您可以在关闭作为辅助端口运行的实例之前,将服务器重新配置为仲裁器。For this procedure, see Convert Secondary to Arbiter Running on a New Port Number.有关此过程,请参阅将辅助端口转换为在新端口号上运行的仲裁器。
Convert Secondary to Arbiter and Reuse the Port Number将Secondary转换为Arbiter并重用端口号
If your application is connecting directly to the secondary, modify the application so that MongoDB queries don't reach the secondary.如果您的应用程序直接连接到辅助应用程序,请修改该应用程序,使MongoDB查询不会到达辅助应用程序。Shut down the secondary.关闭辅助设备。Remove the secondary from the replica set by calling the通过调用rs.remove()
method.rs.remove()
方法从副本集中删除secondary。Perform this operation while connected to the current primary in在mongosh
:mongosh
中连接到当前primary时执行此操作:rs.remove("<hostname><:port>")
Verify that the replica set no longer includes the secondary by calling the通过调用rs.conf()
method inmongosh
:mongosh
中的rs.conf()
方法,验证副本集是否不再包括secondary:rs.conf()
Move the secondary's data directory to an archive folder.将辅助的数据目录移动到存档文件夹中。For example:例如:mv /data/db /data/db-old
NoteOptional可选的You may remove the data instead.您可以删除数据。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
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:您可以使用与以前相同的端口号。发出类似于以下内容的命令:WarningBefore 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)>
In在mongosh
convert the secondary to an arbiter using thers.addArb()
method:mongosh
中,使用rs.addArb()
方法将secondary转换为仲裁器:rs.addArb("<hostname><:port>")
Verify the arbiter belongs to the replica set by calling the通过调用rs.conf()
method inmongosh
.mongosh
中的rs.conf()
方法来验证仲裁器是否属于副本集。rs.conf()
The arbiter member should include the following:仲裁员应包括以下内容:"arbiterOnly" : true
Convert Secondary to Arbiter Running on a New Port Number将辅助端口转换为在新端口号上运行的仲裁器
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查询不会到达辅助服务器。Create a new, empty data directory to be used with the new port number.创建一个新的空数据目录,用于新的端口号。For example:例如:mkdir /data/db-temp
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:发出类似于以下内容的命令:WarningBefore 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)>
In在连接到当前主节点的mongosh
connected to the current primary, convert the newmongod
instance to an arbiter using thers.addArb()
method:mongosh
中,使用rs.addArb()
方法将新的mongod
实例转换为仲裁器:rs.addArb("<hostname><:port>")
Verify the arbiter has been added to the replica set by calling the通过调用rs.conf()
method inmongosh
.mongosh
中的rs.conf()
方法来验证仲裁器是否已添加到副本集中。rs.conf()
The arbiter member should include the following:仲裁员应包括以下内容:"arbiterOnly" : true
Shut down the secondary.关闭辅助设备。Remove the secondary from the replica set by calling the通过调用rs.remove()
method inmongosh
:mongosh
中的rs.remove()
方法从副本集中删除secondary:rs.remove("<hostname><:port>")
Verify that the replica set no longer includes the old secondary by calling the通过调用rs.conf()
method inmongosh
:mongosh
中的rs.conf()
方法,验证副本集是否不再包括旧的辅助副本:rs.conf()
Move the secondary's data directory to an archive folder.将辅助的数据目录移动到存档文件夹中。For example:例如:mv /data/db /data/db-old
NoteOptional可选的You may remove the data instead.您可以删除数据。