Google Cloud Mongo DB: External IP not connecting

2020-02-01 16:11发布

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条回答
Juvenile、少年°
2楼-- · 2020-02-01 16:21

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.

查看更多
Ridiculous、
3楼-- · 2020-02-01 16:36

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)
查看更多
登录 后发表回答