Skip to content

Instantly share code, notes, and snippets.

@mansurali901
Created May 31, 2018 07:52
Show Gist options
  • Save mansurali901/3e9f08b85170cd1819c950a0e6ae869f to your computer and use it in GitHub Desktop.
Save mansurali901/3e9f08b85170cd1819c950a0e6ae869f to your computer and use it in GitHub Desktop.
Setup Mongo Replica Sets on Ubuntu 16.04
#!/bin/bash
# This script is written to setup mongo replicasets
# There are three replicas for Mongo replication
# Author : Mansur Ul Hasan
# Email : [email protected]
mkdir /var/lib/mongod{1..3}
mongod --replSet burraq --logpath "/var/log/mongodb/mongod1.log" --dbpath /var/lib/mongod1 --port 27017 &
mongod --replSet burraq --logpath "/var/log/mongodb/mongod2.log" --dbpath /var/lib/mongod2 --port 28017 &
mongod --replSet burraq --logpath "/var/log/mongodb/mongod3.log" --dbpath /var/lib/mongod3 --port 29017 &
mongo <<EOF
config = { _id: "burraq", members:[
{ _id : 0, host : "localhost:27017"},
{ _id : 1, host : "localhost:28017"},
{ _id : 2, host : "localhost:29017"} ]
};
EOF
mongo <<EOF
rs.initiate(config);
EOF
mongo <<EOF
rs.status();
EOF
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment