在原有副本集的主节点进行操作:

 

1.1添加数据节点,

#在primary节点上执行

>rs.add( { host: '192.168.254.112:27017', priority: 9 } ) 这个节点被选为主primary


rs.status() ----验证是否添加成功
查看是否有延迟,如下:

MongoDB Enterprise liuhe_rs:PRIMARY> rs.printSlaveReplicationInfo()
source: 10.9.21.178:27017
syncedTo: Tue Nov 26 2019 21:43:22 GMT+0800 (CST)
0 secs (0 hrs) behind the primary
source: 10.9.21.114:27017
syncedTo: Tue Nov 26 2019 21:43:22 GMT+0800 (CST)
0 secs (0 hrs) behind the primary
source: 10.9.21.115:27017
syncedTo: Tue Nov 26 2019 21:43:22 GMT+0800 (CST)
0 secs (0 hrs) behind the primary

如果新添加的状态为STARTUP2,那么你可以重启下新节点,

use  admin
db.shutdownServer()
/usr/bin/mongodb/bin/mongod  -f /etc/mongod.conf#在primary节点上执行
>rs.add( { host: '192.168.254.112:27020', priority: 2 } )      rs.status()  ----验证是否添加成功

 

1.2删除数据节点
rs.remove("10.9.21.115:27017");
rs.remove("192.168.1.112:27019");
再次查看发现没有了115这个同步信息了
MongoDB Enterprise liuhe_rs:PRIMARY> rs.printSlaveReplicationInfo()
source: 10.9.21.178:27017
syncedTo: Tue Nov 26 2019 21:47:12 GMT+0800 (CST)
8 secs (0 hrs) behind the primary
source: 10.9.21.114:27017
syncedTo: Tue Nov 26 2019 21:47:12 GMT+0800 (CST)
8 secs (0 hrs) behind the primary
MongoDB Enterprise liuhe_rs:PRIMARY>

 

1.3添加仲裁节点
rs.addArb("10.9.21.112:27017");
或者
rs.add({host:"192.168.254.112:27018",arbiterOnly:true})rs.status()
{
"_id" : 3,
"name" : "10.9.21.115:27017",
"health" : 1,
"state" : 7,
"stateStr" : 
"ARBITER",
"uptime" : 165,
"lastHeartbeat" : ISODate("2019-11-26T13:55:21.391Z"),
"lastHeartbeatRecv" : ISODate("2019-11-26T13:55:21.150Z"),
"pingMs" : NumberLong(0),
"lastHeartbeatMessage" : "",
"syncingTo" : "",
"syncSourceHost" : "",
"syncSourceId" : -1,
"infoMessage" : "",
"configVersion" : 6
}

 

1.4查看备份节点的复制信息
rs0:PRIMARY> db.printSlaveReplicationInfo()
source: 172.16.250.234:27017
    syncedTo: Thu Nov 15 2018 11:08:36 GMT+0800 (CST)
    0 secs (0 hrs) behind the primary
source: 172.16.250.240:27017
    syncedTo: Thu Jan 01 1970 08:00:00 GMT+0800 (CST)
    1542251316 secs (428403.14 hrs) behind the primary
副本集测试