Adding members to Replica Set on MongoDb
Asked Answered
R

6

20

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!

Rata answered 22/1, 2012 at 19:22 Comment(1)
First place I'd look is in the 'mongodb.log' file for each server. Probably some good hints in there as to (a) whether the servers are talking to each other at all, and if so (b) what the primary server finds objectionable about the joiner.Carpi
P
15

Remove this in your configuration:

bind_ip = 127.0.0.1

That option is currently incompatible with mongodb replica sets.

Pharyngoscope answered 3/12, 2012 at 22:13 Comment(1)
or set it to bind_ip=0.0.0.0Warrantor
A
10

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

Anabal answered 12/7, 2012 at 2:54 Comment(0)
A
3
{
    "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.

Askwith answered 17/1, 2014 at 10:9 Comment(0)
T
2

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.

Tynes answered 23/1, 2012 at 8:45 Comment(0)
C
2

similar problem i had , the solution was to have a keyfile. http://docs.mongodb.org/manual/tutorial/deploy-replica-set-with-auth/#create-the-key-file-to-be-used-by-each-member-of-the-replica-set

Carnot answered 4/9, 2014 at 18:51 Comment(3)
Huh? Is a keyfile necessary, or was the solution a side-effect?Sitdown
a keyfile is necessary in versions newer than 2Carnot
Actually I got a solution working without a keyfile yesterdaySitdown
M
0

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().

Mireillemireles answered 3/3, 2014 at 15:45 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.