|
MongoDB is a master-slave replication master can be more than they can be mainly from the master-slave replication. Here is a realization of a master server using a database from one server arbitration by providing a different port.
one. Start a MongoDB service name application, port 1234
./mongod --replSet application --dbpath data / node1 --port 1234 --oplogSize 1024
Described the successful launch.
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. Start the client port 1234
./mongo --port 1234
Fives. Configuration copies
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})
Back 1 Description added successfully
six. rs.isMaster ()
Seven. Master-slave replication test whether
1. In the main server to add a record
1.1 use test
db.user.insert ({_ id: 1, name: "maybo"})
1.2 Open from the service client
./mongo --port 1235
1.3 Queries
use test
db.user.find ( "{})
SlaveOk = false discovery need to be clear from the current node node
1.4 rs.slaveOk ()
show collections
Master-slave replication has been successful, but the main one minute from the time required to copy. |
|
|
|