首页 > 代码库 > mongo副本集搭建

mongo副本集搭建

mongo副本集搭建

任意一台:
>use admin
>cfg={ _id:"mongo-repl", members:[
{_id:0,host:‘192.168.32.101:27017‘,priority:2},
{_id:1,host:‘192.168.32.102:27017‘,priority:1},
{_id:2,host:‘192.168.32.101:27018‘,arbiterOnly:true}]}

初始化副本集:rs.initiate(cfg)


需要做主库上操作:
use admin
cfg={ _id:"mongo-repl", members:[
{_id:0,host:‘192.168.32.101:27017‘,priority:2},
{_id:1,host:‘192.168.32.102:27017‘,priority:1},
{_id:2,host:‘192.168.32.101:27018‘,arbiterOnly:true}]}

重建副本集:rs.reconfig(cfg)
删除一个节点:rs.remove("192.168.32.102:27017")
添加一个节点:rs.add(hostportstr)

 

mongo副本集搭建