Mongodb Replica set with 2 node only

Target is setup Active/Standby mode. the Mongo Document suggest at least 3 node.
In 2 node setting, it won't auto failover when Node_A down.

After install mongodb on both node.

update /etc/mongodb.conf
Add below line in the conf

replSet=rs0


then restart the mongodb on both node

Login the Mongodb primary node and use mongo shell run below command



cfg = {
    _id :"rs0",
    members:[
        {_id:0 , host ="Node_A:27017",priority:1},
        {_id:1 , host ="Node_B:27017",priority:0,votes=0}
    ]
}

rs.initiate(cfg)

priority:0 make node_B will be secondary.
Votes:0, make sure even node_B not online, node_A still work

make sure the oplogs size is enough for keep the log when the node_b is down


rs.printReplicationInfo()

More Replica method can find below

Remove Primary
remove /etc/mongodb.conf
Comment below line in the conf

replSet=rs0

restart the mongodb
login the drop the local db

留言