Steps:
First, start three processes
1./bin/mongod--dbpath=/home/work/app/mongodb/mongodb-linux-x86_64-amazon-3.2.7/data/r0--logpath=/home/work/ Logs/mongodb/r0.log--fork--port=27017--replset=rs1
2./bin/mongod--dbpath=/home/work/app/mongodb/mongodb-linux-x86_64-amazon-3.2.7/data/r1--logpath=/home/work/ Logs/mongodb/r1.log--fork--port=27018--replset=rs1
2./bin/mongod--DBPATH=/HOME/WORK/APP/MONGODB/MONGODB-LINUX-X86_64-AMAZON-3.2.7/DATA/R2--logpath=/home/work/ Logs/mongodb/r2.log--fork--port=27019--replset=rs1
The most important thing is to declare that three MONGO processes are using a replica set --replset=rs1
Second, the configuration
1, with MONGO client arbitrarily connected to a process./bin/mongo, cut to use admin
var rsconf = {
_id: ' Rs1 ',
members:[
{
_id:0,
Host: ' 192.168.1.201:27107 '
},
{
_id:1,
Host: ' 192.168.1.201:27108 '
},
{
_id:2,
Host: ' 192.168.1.201:27109 '
},
]
}
2, according to the configuration to do replcation set of the first mother of
Rs.initiate (rsconf);
3. Adding nodes
rs.add (' 192.168.1.201:27018 ');
Rs.add (' 192.168.1.201:27019 ');
4. View status
Rs.status ();
5. Deleting nodes
Rs.remove (' 192.168.1.201:27019 ');
If you are using a node, the following error occurs
JavaScript execution Failed:error: {"$err": "Not Master and Slaveok=false", "Code": 13435}
The above error occurs because slave is not allowed to read and write by default
Rs.slaveok ();
MONGDB Copy Set