Tuesday 1 October 2013

Replication in MongoDB

!!!!!!!!!!!!!!!!!!!!!!!
Replication
!!!!!!!!!!!!!!!!!!!!!!!

cd data
mkdir rs1 rs2 rs3
cd..
mongod --replSet m101 --logpath "1.log" --dbpath /data/rs1 --port 27017 --smallfiles
mongod --replSet m101 --logpath "2.log" --dbpath /data/rs2 --port 27018 --smallfiles
mongod --replSet m101 --logpath "3.log" --dbpath /data/rs3 --port 27019 --smallfiles

this shell script (started from mongo folder) should create replica set of 3 servers on Windows

config = { _id: "rs1" , members: [
{_id:0, host: "<here should be name of your computer> : 27017" , priority:0, slaveDelay:5 } ,
{_id:1, host: "<here should be name of your computer> : 27018"} ,
{_id:1, host: "<here should be name of your computer> : 27019"}]


rs.initiate(config)


this commands will initiate replica set, where server with _id:0 will be hidden member