Wednesday, 10 June 2015

How to setup mongodb replSet

Master IP - 172.31.9.122
Replset IP - 172-31-17-152


Step 1 - Install mongoDB

# sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 7F0CEB10

# echo "deb http://repo.mongodb.org/apt/ubuntu "$(lsb_release -sc)"/mongodb-org/3.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.0.list

# sudo apt-get update

# sudo apt-get install -y mongodb-org


Step 2 - vim /etc/mongod.conf

Change
Bind Ip - 172-31-9-122 (your IP)
Replsetname - harish (Your Replset Name)


Note - Be Carefull and change according.

Step 3 - Login into mongo

mongo --host 172.31.9.122

>

rs.initiate(
{_id: "harish",
  members: [
    {
      _id: 1,
      host: "ip-172-31-9-122.ap-southeast-1.compute.internal",
      arbiterOnly: false,
      buildIndexes: true,
      priority: 1
    }
  ]
}
)

Step 4 - Install MongoDB with step 1

Step 5 -  vim /etc/mongod.conf

Change
Bind Ip - 172-31-17-152 (your IP)
Replsetname - harish (Your Replset Name)

Step 6 - Add you replset
Login to you master mongo
mongo --host 172.31.9.122
>
 rs.add('ip-172-31-17-152.ap-southeast-1.compute.internal:27017')


Note -
service mongod start
service mongod stop
service mongod status

If not running then go /var/lib/mongod/mongo.lock and delete mongo.lock file then start you mongod








No comments:

Post a Comment