replica set多服务器主从,添加,删除节点,肯定会经常遇到的。下面详细说明一下,添加,删除节点的2种方法。 一,利用rs.reconfig,来添加,删除节点 1,添加节点 repmore:PRIMARY config = {_id:"repmore",members:[{_id:0,host:'127.0.0.1:27017',priorit
replica set多服务器主从,添加,删除节点,肯定会经常遇到的。下面详细说明一下,添加,删除节点的2种方法。
一,利用rs.reconfig,来添加,删除节点
1,添加节点
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}]}; //添加节点
repmore:PRIMARY> rs.reconfig(config); //使配置生效
repmore:PRIMARY> rs.status(); //查看节点状态
节点添加成功。
注意:新增节点的replSet要和其他节点要一样
2,删除节点
repmore:PRIMARY> config = {_id:"repmore",members:[{_id:0,host:'127.0.0.1:27017',priority :2}]}; //删除节点
repmore:PRIMARY> rs.reconfig(config); //使配置生效
repmore:PRIMARY> rs.status(); //查看节点状态
二,利用rs.add和rs.remove来添加删除节点
repmore:PRIMARY> rs.add("127.0.0.1:27018"); //添加节点
repmore:PRIMARY> rs.remove("127.0.0.1:27018"); //删除节
注意:利用rs.add和rs.remove是不用rs.reconfig来使用配置生效的。

replica set多服务器主从,添加,删除节点,肯定会经常遇到的。下面详细说明一下,添加,删除节点的2种方法。
一,利用rs.reconfig,来添加,删除节点
1,添加节点
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}]}; //添加节点
repmore:PRIMARY> rs.reconfig(config); //使配置生效
repmore:PRIMARY> rs.status(); //查看节点状态
节点添加成功。
注意:新增节点的replSet要和其他节点要一样
2,删除节点
repmore:PRIMARY> config = {_id:"repmore",members:[{_id:0,host:'127.0.0.1:27017',priority :2}]}; //删除节点
repmore:PRIMARY> rs.reconfig(config); //使配置生效
repmore:PRIMARY> rs.status(); //查看节点状态
二,利用rs.add和rs.remove来添加删除节点
repmore:PRIMARY> rs.add("127.0.0.1:27018"); //添加节点
repmore:PRIMARY> rs.remove("127.0.0.1:27018"); //删除节
注意:利用rs.add和rs.remove是不用rs.reconfig来使用配置生效的。
Stellungnahme:Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn