MongoDB Replication Configuration

                    MongoDB Replication Configuration:

while replication in mongodb if it show error like "not master" then run rs.slaveOk() command on secondary node side it will solve issue.
====================================================
Replication- mongoDB

1.Start by creating a data directory for each replica set member:
mkdir /data/node1
mkdir /data/node2
mkdir /data/arbiter

2.
mongod --replSet myapp --dbpath /data/node1 --port 40000
mongod --replSet myapp --dbpath /data/node2 --port 40001
mongod --replSet myapp --dbpath /data/arbiter --port 40002

3.
run mongo hostname:40000 to rum client on primary, and then run the rs.initiate() command:
> rs.initiate()
{
"info2" : "no configuration explicitly specified -- making one",
"me" : "arete:40000",
"info" : "Config now saved locally. Should come online in about a minute
.",
"ok" : 1
}

4.You can now add the other two members using rs.add():
>rs.add("localhost:40001")
{"ok" : 1 }
>rs.add("arete.local:40002", {arbiterOnly: true})
{"ok" : 1 }

5. to verify:
>db.isMaster()
>rs.status()
>rs.help()

6. now you can add 2 replication machine and then disconnect/shutdown one machine and see the out put of rs.status() command.

You will find that:
1. There is 1 primary and others are secondary machine.
2 . If you disconnect primary then secondary machine will become primary.
3. If you up old primary again then that will become secondary now.
that it. Thanks

Please write comment if you have any doubt.

=====================================================

Comments

Popular posts from this blog

Setup Nginx as a Reverse Proxy for Thingsboard running on different port/server

How to auto re-launch a YARN Application Master on a failure.

Read JSON File in Cassandra