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:这两种程序在操作上是等效的:
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.有关此过程,请参阅将在新端口号上运行的辅助仲裁器转换为仲裁器。
For the following MongoDB versions, 对于以下MongoDB版本,对于具有仲裁器的副本集,与pv1
increases the likelihood of w:1
rollbacks compared to pv0
(no longer supported in MongoDB 4.0+) for replica sets with arbiters:pv0
(MongoDB 4.0+不再支持)相比,pv1
增加了w:1
回滚的可能性:
See Replica Set Protocol Version.请参阅副本集协议版本。
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
中的当前主电源时执行此操作:
rs.remove("<hostname><:port>")
Verify that the replica set no longer includes the secondary by calling the 通过调用rs.conf()
method in mongosh
:mongosh
中的rs.conf()
方法,验证副本集不再包含辅助副本:
rs.conf()
Move the secondary's data directory to an archive folder. For example:将辅助设备的数据目录移动到存档文件夹。例如:
mv /data/db /data/db-old
You may remove the data instead.您可以改为删除数据。
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
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:您可以使用以前使用的相同端口号。发出类似于以下内容的命令:
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)>
In 在mongosh
convert the secondary to an arbiter using the rs.addArb()
method:mongosh
中,使用rs.addArb()
方法将辅助设备转换为仲裁器:
rs.addArb("<hostname><:port>")
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
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:发出类似于以下内容的命令:
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)>
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>")
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
Remove the secondary from the replica set by calling the 通过调用rs.remove()
method in mongosh
: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 in mongosh
:mongosh
中的rs.conf()
方法,验证副本集不再包含旧的辅助副本:
rs.conf()
Move the secondary's data directory to an archive folder. 将辅助设备的数据目录移动到存档文件夹。For example:例如:
mv /data/db /data/db-old
You may remove the data instead.