Official documents:
http://docs.mongodb.org/manual/replication/
Replication sets multiple servers maintain the same copy of data
How to use the replication set first step
Start Mongod is to specify the replica set name, either by adding –replset name or by setting the Replication.replsetname setting in the configuration file
Like what:
mongod --port 270217 --dbpath /mongo/database --logpath /mongo/log/mongo.log --replSet repl_test --smallfiles &mongod --port 270218 --dbpath /mongo2/database --logpath /mongo2/log/mongo.log --replSet repl_test --smallfiles &mongod --port 270219 --dbpath /mongo3/database --logpath /mongo3/log/mongo.log --replSet repl_test --smallfiles &
Step Two
into one of the
Like what:
mongo --port 27017
Then define the parameters of Rs.initiate (rsconf) rsconf
rsconf = { _id:‘repl_test‘, members: [ { _id:0,host:‘127.0.0.1:27017‘ }, { _id:1,host:‘127.0.0.1:27018‘ }, { _id:2,host:‘127.0.0.1:27019‘ }, ]}
Step Three
Initializing a replication set
rs.initiate(rsconf)
Operation on a replica set
viewing replication Set Information
Default _id:0 The Mongod primary node
Delete a node
rs.remove(host)
Adding nodes
rs.add(host)rs.reconfig(rsconf)
Default access to the primary node can be manipulated, if you enter the secondary node, want to do crud operations need to run
rs.slaveOk()
If the primary node goes down, one of the remaining nodes will automatically become the master node
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
MongoDB Learning Note--Replication copy set