3
votes

I have created a ready to go MongoDB server on Google Cloud using the default parameters. Everything is working fine between them (there is communication and I can add DBs and collections). However, I can't connect to MongoDB on any external machine. I created the firewall rules in GCP allowing all the connections ("0.0.0.0./0") on the port 27017.

I am running the command:

giuseppe@ubuntu:~$ mongo --host rs0/104.154.xx.xxx,173.255.xxx.xxx,104.197.xxx.xxx 



giuseppe@ubuntu:~$ mongo --host rs0/104.154.xxx.xxx:27017,173.255.xxx.xxx:27017,104.197.xxx.xxx:27017

I'm getting the same error on both of them. I don't know how to resolve this issue.

connecting to: rs0/104.154.41.xxx,173.255.xxx.xxx,104.197.22.xxx:27017/test
2015-03-18T19:47:33.770-0500 starting new replica set monitor for replica set rs0 with seeds 104.154.41.xxx:27017,104.197.22.1xx:27017,xx.255.114.xxx:27017
2015-03-18T19:47:33.770-0500 [ReplicaSetMonitorWatcher] starting
2015-03-18T19:47:34.119-0500 changing hosts to rs0/mongo-db-jff3:27017,mongo-db-vnc4:27017 from rs0/104.154.41.246:27017,1xx.197.22.xxx:27017,173.255.1xx.xx:27017
2015-03-18T19:47:34.493-0500 getaddrinfo("mongo-db-vnc4") failed: Name or service not known
2015-03-18T19:47:34.511-0500 getaddrinfo("mongo-db-jff3") failed: Name or service not known
2015-03-18T19:47:34.512-0500 Error: connect failed to replica set rs0/104.154.xxx.xxx:27017,173.2xx.xxx.68:27017,104.197.22.xxx:27017 at src/mongo/shell/mongo.js:148

EDIT:

Here are my firewall settings.

2
What, if any, does this have to do with google-app-engine? Why do people tag so many Qs that way that clearly are not GAE questions but have to do with other of the many products in GCP, such as (I suspect here) google-compute-engine? Do you realize how much harder you're making it for us to offer you free support, when you mis-tag questions like that?!Alex Martelli
I have the same issue with GCP, I set a new firewall rules with the port 27017 with IP ranges 0.0.0.0/0 then i added the target tag in my vm instances. I can connect and view other mongo instances (members) inside instace with SSH, everything works correctly, but outside I can't connect with "mongodb://user:pass@ip-1:27017,ip-2:27017,ip-3:27017/admin?replicaSet=rs-0" only I can connect when I delete de replicaset, "mongodb://user:pass@ip-1:27017,ip-2:27017,ip-3:27017/admin", I dont know why...Hector
It is the same error described in community.bitnami.com/t/…Hector

2 Answers

3
votes

Did you

  • configure the firewall rule in Google cloud console
  • provide a tag in your firewall rule
  • tag your instance with the same tag as the firewall rule

?

I explained how to open a port to the outside world in detail over here. Replace with your own port number.

0
votes

I belive the issue here is that the ReplicaSetMonitorWatcher is changing hosts to rs0/mongo-db-jff3:27017, where mongo-db-jff3 is not reachable from your network. You need to configure the hosts in the replica set to something that you can reach (static IP or URL).

https://docs.mongodb.com/manual/tutorial/change-hostnames-in-a-replica-set/

Quick example, mongo into your PRIMARY (SECONDARY if you want to do it no downtime):

cfg = rs.conf()
cfg.members[0].host = "mongodb0.example.net:27017"
cfg.members[1].host = "mongodb1.example.net:27017"
rs.reconfig(cfg)