Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding members to Replica Set on MongoDb

Tags:

I am trying to create a replica set with MongoDb, the servers hostnames are:

hostname hostname-1 hostname-2

Each of these has all the relevant hostnames detailed in their /etc/hosts file (They;re all running Ubuntu 10.04 64-bit)

When I do an rs.initiate on one node everything seems to start well. Running rs.status(); shows:

{
    "set" : "vega",
    "date" : ISODate("2012-01-22T19:15:55Z"),
    "myState" : 1,
    "members" : [
        {
            "_id" : 0,
            "name" : "hostname:27017",
            "health" : 1,
            "state" : 1,
            "stateStr" : "PRIMARY",
            "optime" : {
                "t" : 1327254848000,
                "i" : 1
            },
            "optimeDate" : ISODate("2012-01-22T17:54:08Z"),
            "self" : true
        }
    ],
    "ok" : 1
}

The problem comes when I try to add a new member to the replica set. I use the command rs.add(hostname-1); and I get the following error:

{
    "assertion" : "need most members up to reconfigure, not ok : vega-1:27017",
    "assertionCode" : 13144,
    "errmsg" : "db assertion failure",
    "ok" : 0
}

I've tried numerous combinations of using the hostname, IP address, both with and without the port number and I always get the same problem. The hostname is resolving, i've tried ping hostname-1 and it works fine.

Does anybody have any ideas as to what could be causing this issue?

Unfortunately in the Mongo documentation there are no examples of setting up a replica set in the real world scenario, only using three instances on the same machine which is clearly useless.

Thanks in advance for any help!

like image 756
sicr Avatar asked Jan 22 '12 19:01

sicr


People also ask

What is the maximum number of members in a replica set?

A replica set can have up to 7 voting members. If you have an even number of voting members, deploy another data bearing voting member or, if constraints prohibit against another data bearing voting member, an arbiter. An arbiter does not store a copy of the data and requires fewer resources.

How many types of members exist in replica set?

How many types of members exist in replica set? Explanation: There are two members in replica set-primary and secondary.


2 Answers

Remove this in your configuration:

bind_ip = 127.0.0.1

That option is currently incompatible with mongodb replica sets.

like image 160
Reigner S. Yrastorza Avatar answered Oct 07 '22 18:10

Reigner S. Yrastorza


That error happens when you're adding nodes that aren't "up" (yet). It sounds like either "hostname-1" is unreachable (not in /etc/hosts, no DNS) or it is reachable but isn't running mongodb with the replSet configuration parameter set

like image 35
phatduckk Avatar answered Oct 07 '22 18:10

phatduckk