Tuesday, April 24, 2018

Basic Replication Setup with Arbiter - MongoDB

Basic Replication Setup with Arbiter


Arbiter

  • Arbiters are mongod instances that are part of a replica set
  • It does not hold any data
  • It only participates in election during failover
  • If a replica set has an even number of members, add an arbiter
  • Arbiters have minimal resource requirements and do not require dedicated hardware.


Let’s see an example with Arbiter

Servers:

ec2-34-228-80-121.compute-1.amazonaws.com - data
ec2-54-147-246-184.compute-1.amazonaws.com - data
ec2-54-243-20-99.compute-1.amazonaws.com - Arbiter

Note:

  • Please follow the same steps which is mentioned in the previous post Basic Replication Setup till adding replica set member.
  • Config file also as same as the replica set member
  • There will a small change in adding an Arbiter

 Assuming that all 3 servers are up and running

Connect a mongo shell to one of the mongod instances.

ec2-34-228-80-121.compute-1.amazonaws.com
# mongo




Initiate the replica set.


# rs.initiate()





Add the Replica Set Members

# rs.add(“ec2-54-147-246-184.compute-1.amazonaws.com:27017”)
# rs.addArb(“ec2-54-243-20-99.compute-1.amazonaws.com:27017”)
 



View the replica set configuration.

# rs.conf()

Here you can see arbiterOnly : true in the Arbiter node

learning:PRIMARY> rs.conf()
{
        "_id" : "learning",
        "version" : 5,
        "protocolVersion" : NumberLong(1),
        "members" : [
                {
                        "_id" : 0,
                        "host" : "ip-172-31-29-148.ec2.internal:27017",
                        "arbiterOnly" : false,
                        "buildIndexes" : true,
                        "hidden" : false,
                        "priority" : 1,
                        "tags" : {

                        },
                        "slaveDelay" : NumberLong(0),
                        "votes" : 1
                },
                {
                        "_id" : 1,
                        "host" : "ec2-54-147-246-184.compute-1.amazonaws.com:27017",
                        "arbiterOnly" : false,
                        "buildIndexes" : true,
                        "hidden" : false,
                        "priority" : 1,
                        "tags" : {

                        },
                        "slaveDelay" : NumberLong(0),
                        "votes" : 1
                },
                {
                        "_id" : 2,
                        "host" : "ec2-54-243-20-99.compute-1.amazonaws.com:27017",
                        "arbiterOnly" : true,
                        "buildIndexes" : true,
                        "hidden" : false,
                        "priority" : 1,
                        "tags" : {

                        },
                        "slaveDelay" : NumberLong(0),
                        "votes" : 1
                }
        ],
        "settings" : {
                "chainingAllowed" : true,
                "heartbeatIntervalMillis" : 2000,
                "heartbeatTimeoutSecs" : 10,
                "electionTimeoutMillis" : 10000,
                "getLastErrorModes" : {

                },
                "getLastErrorDefaults" : {
                        "w" : 1,
                        "wtimeout" : 0
                },
                "replicaSetId" : ObjectId("5aded4fcfbfb90cc683df7b3")
        }
}
learning:PRIMARY>


To check the status of Arbiter node

# rs.status()

Here you can find "stateStr" : "ARBITER" in the Arbiter node

learning:PRIMARY> rs.status()
{
        "set" : "learning",
        "date" : ISODate("2018-04-24T07:05:17.699Z"),
        "myState" : 1,
        "term" : NumberLong(1),
        "heartbeatIntervalMillis" : NumberLong(2000),
        "members" : [
                {
                        "_id" : 0,
                        "name" : "ip-172-31-29-148.ec2.internal:27017",
                        "health" : 1,
                        "state" : 1,
                        "stateStr" : "PRIMARY",
                        "uptime" : 588,
                        "optime" : {
                                "ts" : Timestamp(1524553218, 1),
                                "t" : NumberLong(1)
                        },
                        "optimeDate" : ISODate("2018-04-24T07:00:18Z"),
                        "electionTime" : Timestamp(1524552956, 2),
                        "electionDate" : ISODate("2018-04-24T06:55:56Z"),
                        "configVersion" : 5,
                        "self" : true
                },
                {
                        "_id" : 1,
                        "name" : "ec2-54-147-246-184.compute-1.amazonaws.com:27017",
                        "health" : 1,
                        "state" : 2,
                        "stateStr" : "SECONDARY",
                        "uptime" : 308,
                        "optime" : {
                                "ts" : Timestamp(1524553218, 1),
                                "t" : NumberLong(1)
                        },
                        "optimeDate" : ISODate("2018-04-24T07:00:18Z"),
                        "lastHeartbeat" : ISODate("2018-04-24T07:05:16.512Z"),
                        "lastHeartbeatRecv" : ISODate("2018-04-24T07:05:16.512Z"),
                        "pingMs" : NumberLong(0),
                        "syncingTo" : "ip-172-31-29-148.ec2.internal:27017",
                        "configVersion" : 5
                },
                {
                        "_id" : 2,
                        "name" : "ec2-54-243-20-99.compute-1.amazonaws.com:27017",
                        "health" : 1,
                        "state" : 7,
                        "stateStr" : "ARBITER",
                        "uptime" : 299,
                        "lastHeartbeat" : ISODate("2018-04-24T07:05:16.511Z"),
                        "lastHeartbeatRecv" : ISODate("2018-04-24T07:05:13.468Z"),
                        "pingMs" : NumberLong(0),
                        "configVersion" : 5
                }
        ],
        "ok" : 1
}
learning:PRIMARY>

Done…
 
 
 

No comments:

Post a Comment