4

I have MongoDb installed on two Ubuntu 16 VMs both hosted on the same network on Google Cloud's Compute Engine. The connecting instance has Internal IP 10.132.0.2, the database instance has 10.132.0.3. (https://gyazo.com/59f9086591a1d6673e8194a50fff51e1)

I've opened tcp 27017 for the instance I wish to connect to. I added this using the gcloud console commands. (https://gyazo.com/0d158aa735c6967e278fac63d598721f) I have also tried opening tcp:1-65535;udp:1-65535 for testing purposes, with no result.

Running mongo on either instance will properly connect to it's own mongodb service, so they're installed, running and working.

On the database instance, netstat -a | grep :27017 displays that it's listening correctly. (https://gyazo.com/0f4fb3c49a51f6886ff4ccb2d44a132a)

On the database instance, the config file at /etc/mongod.conf of the is edited so bind_ip also has the Internal IP of said instance. (https://gyazo.com/20fb669506e7e67ef49fdcf9af6df144) I have also tried 0.0.0.0 for testing purposes, with no result.

Running mongo 10.132.0.3 from the connecting instance results in Failed to connect to 10.132.0.3:27017, reason: errno:111 Connection refused. (https://gyazo.com/9e5aec732e3f09cbfa62a4d78df3620f)

Running nmap -p 27017 10.132.0.3 on the connecting instance shows port 27017 is closed. (https://gyazo.com/7ccd905db5b9946d616176b9ab75479c)

I'm at an utter loss, please help me out? :<

Taelia
  • 591
  • 3
  • 20

2 Answers2

2

Your mongodb servers are only listening on the localhost address (127.0.0.1), rather than on INADDR_ANY (shows up as *:27017 in netstat).

Like this question, it looks like you need to set bind_ip = 0.0.0.0 in your mongod.conf.

Community
  • 1
  • 1
E. Anderson
  • 3,405
  • 1
  • 16
  • 19
  • Thanks, it worked perfectly for me. Just realized that mongodb installation guide also mentions this https://docs.mongodb.com/manual/reference/configuration-options/#mongodb-setting-net.bindIp – Cool Coder Jul 22 '21 at 18:29
0

Thanks to E. Anderson's link I managed to solve this issue; suddenly turning this into a duplicate. However, neither this answer nor the answer in the link were "correct".

The solution to set bind_ip=0.0.0.0 in mongod.conf is rather dangerous, besides, it didn't work. However, killing the mongodb service, and then manually running mongod --bind_ip 10.132.0.3 actually allowed my two instances to connect.

Which.. means that javadude's reply in the other thread saying "But I still dont get it. Why this did not work when I modified mongo.conf file to accept bind_ip 0.0.0.0"` also goes for me. I don't get it, but, it definitely worked to manually give it an ip-address to listen on.

Taelia
  • 591
  • 3
  • 20
  • how did you kill the mongodb service? I am having similar issue ETA I did it with sudo service mongod stop - thanks this fixed it! – Luke Barker May 27 '16 at 19:35