发布于 2015-09-14 14:53:03 | 96 次阅读 | 评论: 0 | 来源: 网络整理
If you have a secondary in a replica set that no longer needs to hold a copy of the data but that you want to retain in the set to ensure that the replica set will be able to elect a primary, you can convert the secondary into an arbiter. This document provides two equivalent procedures for this process.
Both of the following procedures are operationally equivalent. Choose whichever procedure you are most comfortable with:
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 a Secondary to an 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 a Secondary to an Arbiter Running on a New Port Number.
也可以参考
If your application is connecting directly to the secondary, modify the application so that MongoDB queries don’t reach the secondary.
Shut down the secondary.
Remove the secondary from the replica set by calling the rs.remove() method. Perform this operation while connected to the current primary in the mongo shell:
rs.remove("<hostname>:<port>")
Verify that the replica set no longer includes the secondary by calling the rs.conf() method in the mongo shell:
rs.conf()
Move the secondary’s data directory to an archive folder. For example:
mv /data/db /data/db-old
Optional
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. For example:
mkdir /data/db
Restart the 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:
mongod --port 27021 --dbpath /data/db --replSet rs
In the mongo shell convert the secondary to an arbiter using the rs.addArb() method:
rs.addArb("<hostname>:<port>")
Verify the arbiter belongs to the replica set by calling the rs.conf() method in the mongo shell.
rs.conf()
The arbiter member should include the following:
"arbiterOnly" : true
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.
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. Issue a command similar to the following:
mongod --port 27021 --dbpath /data/db-temp --replSet rs
In the mongo shell connected to the current primary, convert the new mongod instance to an arbiter using the rs.addArb() method:
rs.addArb("<hostname>:<port>")
Verify the arbiter has been added to the replica set by calling the rs.conf() method in the mongo shell.
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 in the mongo shell:
rs.remove("<hostname>:<port>")
Verify that the replica set no longer includes the old secondary by calling the rs.conf() method in the mongo shell:
rs.conf()
Move the secondary’s data directory to an archive folder. For example:
mv /data/db /data/db-old
Optional
You may remove the data instead.