1、在副本集中移除一个node
remove
Arguments
• hostname – Specify one of the existing hosts to remove from the current replica set.
Removes the node described by the hostname parameter from the current replica set. This function will
disconnect the shell briefly and forces a reconnection as the replica set renegotiates negotiates which node will
be primary. As a result, the shell will display an error even if this command succeeds.
Note: Before running the rs.remove() (page 67) operation, you must shut down the replica set member that
you’re removing. Changed in version 2.2: This procedure is no longer required when using rs.remove()
(page 67), but it remains good practice.
二、移除node6
1、关闭node6
ctrl+c或者use admin db.shutdownServer()或者kill -2 /-15 pid干掉它
2、移除node6
PRIMARY> rs.remove("lenovo-2395031b:29996");
Fri Oct 19 13:42:14 DBClientCursor::init call() failed
Fri Oct 19 13:42:14 query failed : admin.$cmd { replSetReconfig: { _id: "rs", ve
rsion: 9, members: [ { _id: 0, host: "lenovo-2395031b:29991" }, { _id: 1, host:
"lenovo-2395031b:29992" }, { _id: 2, host: "lenovo-2395031b:29993" }, { _id: 3,
host: "lenovo-2395031b:29994" }, { _id: 4, host: "lenovo-2395031b:29995" } ] } }
to: 127.0.0.1:29991
Fri Oct 19 13:42:14 Error: error doing query: failed shell/collection.js:151
Fri Oct 19 13:42:14 trying reconnect to 127.0.0.1:29991
Fri Oct 19 13:42:14 reconnect 127.0.0.1:29991 ok
3、移除后状态
PRIMARY> rs.conf();
{
"_id" : "rs",
"version" : 9,
"members" : [
{
"_id" : 0,
"host" : "lenovo-2395031b:29991"
},
{
"_id" : 1,
"host" : "lenovo-2395031b:29992"
},
{
"_id" : 2,
"host" : "lenovo-2395031b:29993"
},
{
"_id" : 3,
"host" : "lenovo-2395031b:29994"
},
{
"_id" : 4,
"host" : "lenovo-2395031b:29995"
}
]
}
4、查看同步状态
PRIMARY> db.printSlaveReplicationInfo();
source: lenovo-2395031b:29992
syncedTo: Fri Oct 19 2012 13:42:14 GMT+0800
= 1282 secs ago (0.36hrs)
source: lenovo-2395031b:29993
syncedTo: Fri Oct 19 2012 13:42:14 GMT+0800
= 1282 secs ago (0.36hrs)
source: lenovo-2395031b:29994
syncedTo: Fri Oct 19 2012 13:42:14 GMT+0800
= 1282 secs ago (0.36hrs)
source: lenovo-2395031b:29995
syncedTo: Fri Oct 19 2012 13:42:14 GMT+0800
= 1282 secs ago (0.36hrs)