Testing mongo replication on OSX
mongodb
Solution
Found it!
It turns out that when one installs MongoDB on OSX with brew a configuration file is created at /usr/local/etc/mongo.conf. In this file there was the line:
# Only accept local connections bind_ip = 127.0.0.1
Well, if you look at the log the rsStart error was:
Sun Nov 18 18:32:56 [rsStart] trying to contact macbookpro.local:27001
Sun Nov 18 18:32:56 [rsStart] couldn't connect to macbookpro.local:27001: couldn't connect to server macbookpro.local:27001
Sun Nov 18 18:32:56 [rsStart] replSet can't get local.system.replset config from self or any seed (yet)
and if I ping macbookpro.local the IP address returned was 192.168.41.1. 192.168.41.1 <> 127.0.0.1 so mongod was refusing to respond. Removing this line from the configuration allowed be to setup replication successfully.
sheesh. I am such an idiot. Looked for hours at this and kept thinking that the machine name when connected to the network was 127.0.0.1. Let this be a lesson to you---don't get old!
Problem
In two different terminals, I start up mongod with: ``` mongod --dbpath 1 --port 27001 --smallfiles --oplogSize 50 --logpath log.1 --replSet test mongod --dbpath 2 --port 27002 --smallfiles --oplogSize 50 --logpath log.2 --replSet test ``` (data subdirectories 1 and 2 already created). I go into a third window and run the mongo shell against one of the mongod instances ``` mongo --port 27001 ``` In the shell, I setup a configuration as ``` cfg = { _id: "test", members: [ {_id:0, host: "localhost:27001"}, {_id:1, host:"localhost:27002"} ] } ``` then run: ``` use admin rs.initiate(cfg) ``` The response from the shell is: ``` { "startupStatus" : 4, "info" : "hotest", "errmsg" : "all members and seeds must be reachable to initiate set", "ok" : 0 } ``` The logfile for instance on port 27001 reports: ``` Sun Nov 18 18:32:56 [rsStart] trying to contact macbookpro.local:27001 Sun Nov 18 18:32:56 [rsStart] couldn't connect to macbookpro.local:27001: couldn't connect to server macbookpro.local:27001 Sun Nov 18 18:32:56 [rsStart] replSet can't get local.system.replset config from self or any seed (yet) ``` It appears that the rs.initiate(cfg) cannot connect to the mongod instance on port 27001. But when I run mongod without --replSet the mongo shell connects just fine. It isn't clear where I am screwing up but I will bet it is obvious.