MongoDB Master-slave replication is a master can be more from and can master the master-slave replication. Here is the implementation of a master one from an arbiter server using a database server by providing a different port.
A Start a MongoDB service name is application, port is 1234
./mongod--replset Application--dbpath data/node1--port 1234--oplogsize 1024
Indicates that the startup was successful.
Two Open Client
./mongo--port 1234
Three Start Node2,node3
./mongod--replset Application--dbpath data/node2--port 1235--oplogsize 1024
./mongod--replset Application--dbpath data/node3--port 1236--oplogsize 1024
Four The boot port is a 1234 client
./mongo--port 1234
Five Configuration Replicas
CONFIG={_ID: "Application", members:[]}
Config.members.push ({_id:0,host: "localhost:1234"})
Config.members.push ({_id:1,host: "localhost:1235"})
Config.members.push ({_id:2,host: "localhost:1236",arbiteronly:true})
Return 1 Description Add success
Six Rs.ismaster ()
Seven Testing whether to implement master-slave replication
1. Add a record to the master server
1.1 Use Test
Db.user.insert ({_id:1,name: "Maybo"})
1.2 Open from service client
./mongo--port 1235
1.3 Queries
Use test
Db.user.find ("{}")
Discover Slaveok=false the current node needs to be clear from the node.
1.4 Rs.slaveok ()
Show collections
Indicates that master-slave replication has succeeded, but the master-slave replication takes a minute.
MongoDB replication Mechanism Instance