2

I am having problems setting up a mongo replica set. I have 2 servers and want one to be primary and one to be secondary.

On primary machine in mongod.conf:

replSet=rs1

Then in the console I type:

rs.initiate()

Which works great. rs.config() shows:

{
  _id: "rs1",
  version: 1,
  members: [
    {
      _id: 0,
      host: "myhost1:27017"
    }
  ]
}

This is where things get messy. What am I supposed to do on the second machine? I have modified the mongod.conf to point to the same replica set name 'rs1'. I start the sever and all is well.

Am I supposed to do an rs.initiate() on the second machine? If so both instances now think that they are the 'PRIMARY'.

If I try to do an rs.add(...) on the first server to add the second server:

rs.add("myhost2:27017")

I get an error:

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

if I do an rs.initiate() on the second machine and then an rs.config() I get:

{
  _id: "rs1",
  version: 1,
  members: [
    {
      _id: 0,
      host: "myhost2:27017"
    }
  ]
}

Any ideas?

EDIT:

Here is my /etc/hosts file in case I messed something up there:

host1:

127.0.0.1   myhost1
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost4.localdomain6

host2:

127.0.0.1   myhost2
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost4.localdomain6
  • Can the 2 machines see each other over the network on the port stated? check a telnet and ensure you get connectivity first and let us know. Also, show us your /opt/config/mongodb file please. – Ali Razeghi Sep 9 '15 at 1:27
  • They can see each other. I have tried starting over a number of times with no luck. added what is in my /etc/hosts file just in case that is an issue. – lostintranslation Sep 9 '15 at 1:39
1

tl;dr

Your hosts were unable to resolve the hostnames you gave to actual IPs, since those were missing in the /etc/hosts file.

How to solve

  1. The hosts files on the all the machines must resolve the IPs of the respective machines to their respective hostnames.

    For example

    192.168.0.1 myhost1
    192.168.0.2 myhost2
    127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
    ::1         localhost localhost.localdomain localhost6 localhost6.localdomain6  
    

    Make sure all hostnames are resolved correctly by pinging each other host from each host, eg.

    myhost1 $ ping myhost2
    
  2. Please read the docs thoroughly and make sure you understood them.

  3. Proceed to step 2 until you really got it.
  4. You only have to call rs.initiate() once and only on one machine, then use rs.add() on the same machine to add replica set members.

With your setup, you need an additional node or an arbiter

Personal note

Please do not take this personal, but you lack basic system administration skills, and that's put politely.

For your own sake: Do not run MongoDB for production until you acquired basic system and MongoDB administration skills!

I'd look for RHCSA first (works for CentOS as well) and M102, M202 and maybe even MongoDB DBA at MongoU later (without basic sysadmin skills, the latter won't help you much).

  • 2
    Hard not to take that personal :/ Non the less I do appreciate you taking time to answer my question. Thanks for the help! – lostintranslation Sep 9 '15 at 10:50
  • 2
    Sure and agreed. However I think its wrong to assume anyones situation. You can't leave a bold title 'Personal note', then say don't take it personal. – lostintranslation Sep 9 '15 at 12:00
  • 1
    Just some feedback of my own, It's really great and helpful that the links to training were included, that's often overlooked. Putting it politely to me though would be "It's great to reach out here for help, if you're running this in production though be careful as there are a lot of other issues that come up which are much more complex. Having this in prod like this could lead to major issues. Consider training before moving too fast. I only state this because in StackExchange we try to keep things really upbeat. Anyways, glad you guys got it resolved! – Ali Razeghi Sep 9 '15 at 19:44
  • 1
    IMHO, the "Personal note" section has no place in SO. It's hostile, elitist and, worst of all, unfriendly. – Andres Kievsky Sep 14 '15 at 13:53
  • 1
    Pointing out an aggressive statement is in no way on par with making the aggressive statement in the first place... "and that's putting it mildly" – Andres Kievsky Sep 14 '15 at 14:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.