In MongoDB1.6, it is easy to add members to the Replica Set as follows:
# Add new members
Rs. add ("192.168.95.210: 10000 ");
# Add new elected members
Rs. addArb ("192.168.95.216: 10001 ");
With this configuration, Mongo automatically synchronizes data to new members.
The remove member command is not provided in version 1.6. It is said that this command is available in version 1.7.
However, we can use replSetReconfig to complete this operation.
Next, we remove a set Member and add a new member. The operation is as follows:
# Stop the MongoDB service on the remove Member
Kill-2 'cat/opt/mongodb_data/mongod. lock'
# Scp the data file of old members to the new server. To speed up the rs_sync Process
Scp suv. * 10.11.15.39:/pvdata/
# Start the MongoDB service on a new member
/Usr/local/mongodb/bin/mongod-fork-shardsvr-port 10000-replSet set2-dbpath/pvdata/mongodb_data-logpath/pvdata/mongodb_log/mongod. log-logappend
# Execute the command on the Master Member of the set
Config = {_ id: 'set2', members :[
{_ Id: 0, host: '192. 168.95.218: 100 '},
{_ Id: 1, host: '10. 11.15.39: 10000 '},
{_ Id: 2, host: '192. 168.95.216: 100', arbiterOnly: true}
]}
Use local
Old_config = db. system. replset. findOne ();
# Note that you need to set the versin of the new config. Otherwise, the version number wrong error will be reported.
Config. version = old_config.version + 1;
Use admin
Db. runCommand ({replSetReconfig: config })
This completes the re-configuration of the Replica Set, removes an old server, and adds a new server of 15.39.
Check the new server mongod. log and you can see:
Wed Oct 27 14:24:19 done allocating datafile/pvdata/mongodb_data/local. ns, size: 16 MB, took 0.049 secs
...
Wed Oct 27 17:55:12 [rs_sync] replSet initialSyncOplogApplication 66500000
Wed Oct 27 17:58:02 [rs_sync] replSet initial sync finishing up
Wed Oct 27 17:58:02 [rs_sync] replSet set minValid = 4cc7f49a: 7b
Wed Oct 27 17:58:02 [rs_sync] building new index on {_ id: 1} for local. replset. minvalid
Wed Oct 27 17:58:02 [rs_sync] done for 0 records 0.052 secs
Wed Oct 27 17:58:02 [rs_sync] replSet initial sync done
Wed Oct 27 17:58:04 [rs_sync] replSet SECONDARY
Finally, it indicates that the new Server has been synced and started successfully as secondary.
We can also see the status of the new set using rs. status:
{
"Set": "set2 ",
"Date": "Wed Oct 27 2010 17:57:39 GMT + 0800 (CST )",
"MyState": 1,
"Members ":[
{
"_ Id": 0,
"Name": "zjm-Hadoop-slave218: 10000 ",
"Health": 1,
"State": 1,
"Self": true
},
{
"_ Id": 1,
"Name": "10.11.15.39: 10000 ",
"Health": 1,
"State": 3,
"Uptime": 1231,
"LastHeartbeat": "Wed Oct 27 2010 17:57:39 GMT + 0800 (CST )"
},
{
"_ Id": 2,
"Name": "192.168.95.216: 10001 ",
"Health": 1,
"State": 7,
"Uptime": 1237,
"LastHeartbeat": "Wed Oct 27 2010 17:57:39 GMT + 0800 (CST )"
}
],
"OK": 1
}