可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
we have an EC2 MongoDB 2.4 instance from Amazon MarketPlace. when i try to access it from my computer using the mongo command like so:
mongo xx-xx-xx-xx-xx.compute-1.amazonaws.com
i get the following error
Error: couldn't connect to server xx-xx-xx-xx-xx.compute-1.amazonaws.com:27017 at src/mongo/shell/mongo.js:147 exception: connect failed
- i can connect to the remote instance using ssh so it is reachable.
- the port is the default port 27017.
- mongod is running and working on the remote instance.
any suggestions on how to fix this?
回答1:
As frisky said, you have to open the port 27017 at the EC2 Security Group Console. (To know more about how to do that: http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/authorizing-access-to-an-instance.html)
But it you also need to change the bind_ip
variable at the /etc/mongodb.conf file. You need to comment the line or assign the ip that will be able to connect the DB to it.
回答2:
Since mongod is running and working on the remote instance, you can access your MongoDB content via
mongo xx-xx-xx-xx-xx.compute-1.amazonaws.com or mongo machine_elastic_IP
Before that you need to open Inbound port for that machine.By-default port 27017 is closed for external world.
For more info refer : http://docs.aws.amazon.com/gettingstarted/latest/wah/getting-started-security-group.html
回答3:
Amazon created mongo security group without 27017 open. opening port 27017 to my pc fixed the issue.
回答4:
Try to access xx-xx-xx-xx-xx.compute-1.amazonaws.com:27017 from browser, if it works then ssh into the instance.
- Stop the mongodb server
- Remove the file
/var/lib/mongodb/mongod.lock
start the mongodb server again, and check if typing mongo
takes into a mongo shell or gives any error.
If the error is present, exit from the instance and again ssh to check for $mongo
, if it opens a mongo shell. Try a reboot after this changes if the error still exists after the above changes.
The only concern here is, before accessing it from any application. Mongodb should work independently in the terminal.
回答5:
EC2 controls access using security group, so make sure that box accessing mongo db host is in the security group
allowed to access this box and port
is enabled for the same security group.
Another problem can be iptables
. Check sudo service iptables status
on the mongodb box and see what are the rules there.
Make sure there you enable appropriate ports as per security
requirement of the box.