replica set from the main multi-server, add, delete nodes, will certainly often encountered. The following elaborate, add, delete nodes of the two methods.
First, the use rs.reconfig, add, delete nodes
1, add a node
to view copy print
repmore: PRIMARY> config = {
_id:"repmore",
members:[{_id:0,host:'127.0.0.1:27017',priority :2},{_id:1,host:'127.0.0.1:27018',priority:1}]
}; // add nodes
repmore: PRIMARY> rs.reconfig (config) ; // validate the configuration
repmore: PRIMARY> rs.status (); // Check node status
node added successfully.
Note: replSet new node to other nodes to the same
2, delete the node
view copy print
repmore: PRIMARY> config = {_id : "repmore", members: [{_ id: 0, host: '127.0.0.1: 27017' , priority: 2}]}; // delete a node
repmore: PRIMARY> rs.reconfig (config) ; // validate the configuration
repmore: PRIMARY> rs.status (); // Check node state
two, and use rs.add rs.remove to add a node to delete
view copy print
repmore: PRIMARY> rs.add ( "127.0.0.1:27018 "); // add nodes repmore: PRIMARY> rs.remove ( "127.0.0.1:27018 "); // delete section Note: use rs.add and rs.remove is not rs.reconfig to use valid configuration.
forward from:
https://blog.csdn.net/yujin2010good/article/details/53781642