0、原理
1、开启副本集节点
mongod --dbpath=D:\Database\MongoDB3\dbc0 --port=27017 --replSet neohope mongod --dbpath=D:\Database\MongoDB3\dbc1 --port=27018 --replSet neohope mongod --dbpath=D:\Database\MongoDB3\dbc2 --port=27019 --replSet neohope
2、初始化副本集
mongo --port 27017 config_rs={_id:'neohope',members:[{_id:0,host:'localhost:27017'},{_id:1,host:'localhost:27018'},{_id:2,host:'localhost:27019'}]} rs.initiate(config_rs) rs.status()
3、增加仲裁服务器
mongod --dbpath D:\Database\MongoDB3\dbc3 --port 27020 --replSet neohope/localhost:27017,localhost:27018,localhost:27019
4、设置仲裁服务器
mongo --port 27017 neohope:PRIMARY> rs.addArb("localhost:27020"); neohope:PRIMARY> rs.status()
5、将备用节点设为被动模式
neohope:PRIMARY> r=rs.conf() neohope:PRIMARY> r.members[2].priority=0 neohope:PRIMARY> rs.reconfig(r) neohope:PRIMARY> rs.status()