sicr
sicr

Reputation: 2218

Adding members to Replica Set on MongoDb

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!

Upvotes: 20

Views: 24168

Answers (6)

user3375540
user3375540

Reputation: 11

You may need to check the mongod is running on the second node before you add the second node to node1. If it is running rs.add() and then check rs.status().

Upvotes: 0

user241
user241

Reputation: 131

{
    "errmsg" : "exception: need most members up to reconfigure, not ok : server2:27017",
    "code" : 13144,
    "ok" : 0
}

I encountered the above error in Mongo 2.4.9. My mistake here is that I didn't specify replSet in the mongo config of the new replica member. rs.add("server2:27017") worked well after.

Upvotes: 3

Reigner S. Yrastorza
Reigner S. Yrastorza

Reputation: 161

Remove this in your configuration:

bind_ip = 127.0.0.1

That option is currently incompatible with mongodb replica sets.

Upvotes: 15

phatduckk
phatduckk

Reputation: 1795

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

Upvotes: 10

Gates VP
Gates VP

Reputation: 45277

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.

Agreed, it's pretty poor. That example should be completely removed from the docs.

There is another way to start a replica set and that is by using the rs.configure() command. You can also specify all three nodes at once and then issue the rs.inititiate().

See here for an example of specifying all nodes before initiating.

See here for more details on the various commands.

Upvotes: 2

Related Questions