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.c
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
The following two steps enabled the remote connection for me:
After that you will be able to connect into you remote mongo instance with mongo --host YOUR_INSTANCE_IP
Amazon created mongo security group without 27017 open. opening port 27017 to my pc fixed the issue.
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.
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 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.
Try to access xx-xx-xx-xx-xx.compute-1.amazonaws.com:27017 from browser, if it works then ssh into the instance.
/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.