Create a Directory
Mkdir-p/DATA/R0/DATA/R1/DATA/R2
Declaring an instance
./bin/mongod--port 27017--dbpath/home/workspace/data/r0/--smallfiles--replset RSA--fork--logpath/home/workspace/ Logs/mongo0.log
./bin/mongod--port 27018--dbpath/home/workspace/data/r1/--smallfiles--replset RSA--fork--logpath/home/workspace/ Logs/mongo1.log
./bin/mongod--port 27019--dbpath/home/workspace/data/r2/--smallfiles--replset RSA--fork--logpath/home/workspace/ Logs/mongo2.log
Add configuration
rsconf = {
_id: ' RSA ',
Members
[
{_id:0,
Host: ' 192.168.87.131:27017 '
},
{_id:1,
Host: ' 192.168.87.131:27018 '
},
{_id:2,
Host: ' 192.168.87.131:27019 '
}
]
}
Rs.initiate (rsconf);
Test
- Connecting child nodes:./bin/mongo--port 27017
- Use test
- Db.test.user ({uid:1,name: ' Liliy '})
- Switch to from library:./bin/mongo--port 27019
- Use test
- Show Tables:Error:listCollections failed: {"note": "From ExecCommand", "OK": 0, "errmsg": "Not Master"}
- Rs.slaveok ();
- Show tables
In MongoDB you can only add the MONGO service to the replica set through the master node, judging whether the currently running MONGO service is able to use command Db.ismaster () for the master node.
MongoDB replica set is different from our common master-slave, master and slave after the host outage all services will stop, and replica set after the host outage, the replica will take over the master node becomes the primary node, there will be no downtime.
Resources:
Http://www.cnblogs.com/skyrim/p/5098167.html
MongoDB Replica set schema building