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:
For this procedure, see Convert Secondary to Arbiter and Reuse the Port Number.
For this procedure, see Convert Secondary to Arbiter Running on a New Port Number.
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:
rs.remove()
method. Perform this operation while connected to the current primary in the mongo
shell:
rs.conf()
method in the mongo
shell:
Optional
You may remove the data instead.
mongod
instance. You can reuse the previous name. mongod
instance for the secondary, specifying the port number, the empty data directory, and the replica set. 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. For a complete list of security recommendations, see Security Checklist. At minimum, consider enabling authentication and hardening network infrastructure.
mongo
shell convert the secondary to an arbiter using the rs.addArb()
method:
rs.conf()
method in the mongo
shell.
The arbiter member should include the following:
mongod
instance on the new port number, specifying the new data directory and the existing replica set. 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. For a complete list of security recommendations, see Security Checklist. At minimum, consider enabling authentication and hardening network infrastructure.
mongo
shell connected to the current primary, convert the new mongod
instance to an arbiter using the rs.addArb()
method:
rs.conf()
method in the mongo
shell.
The arbiter member should include the following:
rs.remove()
method in the mongo
shell:
rs.conf()
method in the mongo
shell:
Optional
You may remove the data instead.