Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot connect to MongoDB on AWS (errno:111 Connection refused)

I have followed AWS' instructions (link) for installing MongoDB on AWS, and things seem to work until I try to connect to it.

When I run mongo, I get this connection error:

2015-07-21T23:07:01.188+0000 warning: Failed to connect to 127.0.0.1:27017, reason: errno:111 Connection refused
2015-07-21T23:07:01.188+0000 Error: couldn't connect to server 127.0.0.1:27017 (127.0.0.1), connection attempt failed at src/mongo/shell/mongo.js:146

And that happens even if I comment out the bind_ip setting in the mongod.conf file (a common suggestion on forums), or set it to 0.0.0.0. Mongo did install, as I can run mongo --nodb successfully. Can someone suggest help with my connection problem?

Thanks in advance!

EDIT: Whoops, my script had not the permissions needed to start the mongo daemon, so I started it manually with sudo service mongod start, and now it works! Thanks!

like image 231
Beirutis Avatar asked Jul 22 '15 13:07

Beirutis


1 Answers

"mongo --nodb" will start a "dummy mongod service" and connect you directly into to it.

"mongo" will try to find a mongod service on port 27017 (standard port) on 127.0.0.1 (standard host). Equals: mongo --host 127.0.0.1 --port 27017

To check if your mongod service has started on your server:

$ ps -aux | grep mongo        #check if service runs
$ netstat -nap | grep 27017   #check if port is 27017

Start your mongod service:

$ sudo service mongod start

If still not working, check your logfile:

$ tail -n100 /var/log/mongodb/mongodb.log
like image 86
aldwinaldwin Avatar answered Oct 16 '22 01:10

aldwinaldwin