Skip to content

Instantly share code, notes, and snippets.

@siso
Created April 24, 2015 03:49
Show Gist options
  • Save siso/3b47326f195a7df3a185 to your computer and use it in GitHub Desktop.
Save siso/3b47326f195a7df3a185 to your computer and use it in GitHub Desktop.
MongoDB Replica

Create MongoDB data dirs:

mkdir -p data/rs1 data/rs2 data/rs3

Start three mongod instances:

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

Connect to one of the MongoDB daemons:

mongo --port 27017

Start MongoDB Replica:

config = { _id: "m101", members:[
          { _id : 0, host : "localhost:27017"},
          { _id : 1, host : "localhost:27018"},
          { _id : 2, host : "localhost:27019"} ]
         };
rs.initiate(config);

Look at logfiles:

tail -f *log

Get Replica status:

rs.status()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment