Google Cloud Mongodb:外部IP无法连接

时间:2015-03-19 01:09:10

标签: mongodb google-compute-engine google-cloud-platform

我已使用默认参数在Google Cloud上创建了一个准备好的MongoDB服务器。他们之间的一切都很好(有通信,我可以添加数据库和集合)。但是,我无法在任何外部计算机上连接到MongoDB。 我在GCP中创建了防火墙规则,允许端口27017上的所有连接(“0.0.0.0./0”)。

我正在运行命令:

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

我在两个方面都遇到了同样的错误。我不知道如何解决这个问题。

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

修改

以下是我的防火墙设置。

2 个答案:

答案 0 :(得分:2)

你有

吗?
  • 在Google云端控制台中配置防火墙规则
  • 在防火墙规则中提供标记
  • 使用与防火墙规则相同的标记标记您的实例

我详细解释了如何打开外部世界的端口over here。替换为您自己的端口号。

答案 1 :(得分:0)

我相信这里的问题是ReplicaSetMonitorWatcher将主机更改为rs0 / mongo-db-jff3:27017,在该网络中无法从您的网络访问mongo-db-jff3。您需要将副本集中的主机配置为可以访问的主机(静态IP或URL)。

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

简单的示例,将mongo设置为您的PRIMARY(如果您不希望停机,则使用SENODARY):

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