17

I did a mistake when configuring replica sets in mongodb. I think that what I did wrong is that I did a rs.initialize() on both nodes, which made them confused in some way. I'm not sure.

Now all I want to do is start over, but I couldn't find a way to de-initialize a node. So I followed the advice to delete the local* db files, thus resetting the configurations. I did that, and now nothing works.

> rs.initiate()
{
    "info2" : "no configuration explicitly specified -- making one",
    "me" : "0.0.0.0:27017",
    "errmsg" : "couldn't initiate : can't find self in the replset config",
    "ok" : 0
}
> rs.conf()
null

I tried to remove and reinstall the package (I'm doing this on Ubuntu servers) which just meant that my mongodb.conf disappeared and my init script stopped working. This is of course easy enough to solve.

So how do I start over?

Note: I did look at this answer, but since rs.conf() doesn't work this doesn't work either.

Community
  • 1
  • 1
obeq
  • 675
  • 1
  • 4
  • 14

3 Answers3

54

You'll also get this error if your machine's hostname doesn't map back to 127.0.0.1. Update your /etc/hosts and/or your /etc/hostname, and rs.initiate() with no config should work.

rbrc
  • 872
  • 1
  • 6
  • 13
  • 2
    Fixed the issue for me thanks. If you change your hostname on a cloud instance make sure you add the new hostname to /etc/hosts – Peter Johnson Jul 10 '13 at 16:01
  • 1
    I've also corrected this issue by making sure your assigned IP address is also bound to the bind_ip setting in your /etc/mongod.conf file. Apparently having it bound to 127.0.0.1 isn't always enough. – Felby Apr 16 '14 at 20:08
  • 2
    Had to do something similar: Since the LAN IP resolved, but not 127.0.0.1, I added both - `bind_ip=10.10.1.1,127.0.0.1`. – Felix Frank Oct 15 '14 at 15:18
26

If you force a reconfig with a config that you have generated, does it resolve the issue?

You could do this similar to the follow from the {{mongo}} shell:

> cfg = {
...     "_id" : "rs0",
...     "version" : 1,
...     "members" : [
...         {
...             "_id" : 0,
...             "host" : "0.0.0.0:27017"
...         }
...     ]
... }

>rs.reconfig(cfg, {force:true})

You may need to tune the cfg variable to have your hostname and portname, as the can't find self in new replset config error will be returned to the shell if the repl set can't find the node it is running from in the config.

Andre de Frere
  • 2,703
  • 16
  • 13
9

If you just comment out bind_ip in /etc/mongod.conf this will achieve the correct result so that you can reissue a rs.initiate() command to set-up or reconfig the replica.

occasl
  • 5,303
  • 5
  • 56
  • 81