问题
Just installed mongodb using click-to-deploy in google cloud platform. I have another project, for which I created the mongodb database, where my web application runs. Do I have to open some port or configure something?
回答1:
As the other answers in this thread suggest, mongod
daemon is listening on TCP port 27017
. Therefore, you will need to add a firewall rule on Compute Engine firewall for this port and protocol. This can be done using Google Cloud console or using gcloud
command tool:
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.
回答2:
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
回答3:
Click on the Http or Https checkbox to activate the external ip address so u can use it to access the database
回答4:
On the Mongodb project you should open firewall for port 27017.
MongoDB used ports are listed at:
http://docs.mongodb.org/manual/tutorial/configure-linux-iptables-firewall/
Regards,
Paolo
回答5:
This answer explains how to set the firewall rule for port 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).
I ran into this and after getting both instances on the same network, it was able to connect to the mongo instance by name.
Here's an example of how to set the network for a managed VM in your app.yaml
:
network:
instance_tag: https-server
name: my-node-network
来源:https://stackoverflow.com/questions/28776013/google-cloud-platform-cant-connect-to-mongodb