Communication refused MongoDB errno 111

I have a Linode server running Ubuntu 12.04 LTS and an instance of MongoDB (the service is running and CAN connect locally), with which I cannot connect from an external source.

I added these two rules to my IP tables, where <ip address> is the server on which I want to connect FROM (as indicated in this MongoDB link ):

iptables -A INPUT -s < ip-address > -p tcp --destination-port 27017 -m state --state NEW,ESTABLISHED -j ACCEPT

iptables -A OUTPUT -d < ip-address > -p tcp --source-port 27017 -m state --state ESTABLISHED -j ACCEPT

And I see a rule in my IP table that allows connections to 27017 in and out of <ip address> however, when I try to connect, <ip address> to my mongo database using the following command:

mongo databasedomain/databasename -u username -p password

I get this error:

2014-07-22T23:54:03.093+0000 warning: Failed to connect to databaseserverip:27017, reason: errno:111 Connection refused 2014-07-22T23:54:03.094+0000 Error: couldn't connect to server < ip address >:27017 (databaseserverip), connection attempt failed at src/mongo/shell/mongo.js:148 exception: connect failed

Any help is VERY RATED !!!! Thank!!!

+60
linux mongodb firewall iptables
Jul 23 '14 at 0:12
source share
7 answers

Thanks for helping everyone!

Turns out it was an iptable conflict. Two rules showing the opening of a port (leading to a closed port).

However, one of the comments by aka and the other manu2013 was a problem that I would encounter if not for the conflict.

So! Always remember to edit the /etc/mongod.conf file and set bind_ip = 0.0.0.0 to make connections from the outside.

Also, make sure that you do not have conflicting rules in your iptable for the mongo port (see the link on the mongodb website to configure iptables correctly).

+100
Jul 24 '14 at 18:49
source share

Try the following:

 sudo rm /var/lib/mongodb/mongod.lock sudo service mongodb restart 
+37
Jul 23 '14 at 0:31
source share

These commands fixed the problem for me,

 sudo rm /var/lib/mongodb/mongod.lock sudo mongod --repair sudo service mongod start sudo service mongod status 

If you are behind a proxy server, use: -
export http_proxy = "http: // username: password@company.com: port /"
export https_proxy = "http: // username: password@company.com: port /"

Link: stack overflow

+29
Mar 16 '15 at 17:42
source share

For Ubuntu Server 15.04 and 16.04 you only need to run this command

 sudo apt-get install --reinstall mongodb 
+13
May 11 '16 at 10:38
source share

I did not have a directory /data/db . I created one and gave permission to chmod 777 and it worked for me

+3
Dec 21 '16 at 8:14
source share

Another option is to simply restore the database like this (note: the db0 directory must be created first):

 mongod --dbpath /var/lib/mongodb/ --repairpath /var/lib/mongodb/db0 

It is also an acceptable option in production environments ...

+2
Jan 17 '15 at 19:57
source share

I also had the same problem. Create a directory in dbpath. In my case there was no directory in / data / db. So I created it. Now his job. Be sure to give permission to this directory.

+1
Dec 04 '17 at 9:20
source share



All Articles