简体   繁体   English

Google云端平台 - 无法连接到mongodb

[英]Google Cloud Platform - Can't connect to mongodb

Just installed mongodb using click-to-deploy in google cloud platform. 刚刚在谷歌云平台上使用点击部署安装了mongodb。 I have another project, for which I created the mongodb database, where my web application runs. 我有另一个项目,为此我创建了mongodb数据库,我的Web应用程序运行在该项目中。 Do I have to open some port or configure something? 我必须打开一些端口或配置什么?

As the other answers in this thread suggest, mongod daemon is listening on TCP port 27017 . 正如此线程中的其他答案所示, mongod守护程序正在侦听TCP端口27017 Therefore, you will need to add a firewall rule on Compute Engine firewall for this port and protocol. 因此,您需要在Compute Engine防火墙上为此端口和协议添加防火墙规则 This can be done using Google Cloud console or using gcloud command tool: 这可以使用Google Cloud控制台或使用gcloud命令工具完成:

gcloud compute firewall-rules create allow-mongodb --allow tcp:27017

It is recommended to use target tag with the firewall rule and use this target tag to specify what VM instances the firewall rule should be applied to. 建议将目标标记与防火墙规则一起使用,并使用此目标标记指定应将防火墙规则应用于哪些VM实例。

Adding the port in the firewall is not enough. 在防火墙中添加端口是不够的。 By default the host bind to 127.0.0.1 which needs to be changed to 0.0.0.0 Make changes in the file sudo nano /etc/mongod.conf inside the instance Look for the term bindIp change it to 0.0.0.0 and restart mongodb You will be able to connect to the mongo db now 默认情况下,主机绑定到127.0.0.1,需要更改为0.0.0.0在实例内部对文件sudo nano /etc/mongod.conf进行更改查找术语bindIp将其更改为0.0.0.0并重新启动mongodb您将现在可以连接到mongo db了

单击Http或Https复选框以激活外部IP地址,以便您可以使用它来访问数据库

On the Mongodb project you should open firewall for port 27017. 在Mongodb项目中,您应该为端口27017打开防火墙。

MongoDB used ports are listed at: MongoDB使用的端口列在:
http://docs.mongodb.org/manual/tutorial/configure-linux-iptables-firewall/ http://docs.mongodb.org/manual/tutorial/configure-linux-iptables-firewall/

Regards, 问候,
Paolo 保罗

This answer explains how to set the firewall rule for port 27017 . 答案解释了如何为端口27017设置防火墙规则。

Another issue that could cause this is running your mongodb in a separate network and having your other instances on the default network (or vice versa). 可能导致此问题的另一个问题是在单独的网络中运行您的mongodb并将其他实例放在默认网络上(反之亦然)。

I ran into this and after getting both instances on the same network, it was able to connect to the mongo instance by name. 我遇到了这个问题,在将两个实例都放在同一个网络上之后,它就能够通过名称连接到mongo实例。

Here's an example of how to set the network for a managed VM in your app.yaml : 以下是如何在app.yaml为托管VM设置网络的示例:

network:
  instance_tag: https-server
  name: my-node-network

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM