与MongoDB errno 111的连接被拒绝 [英] Connection refused to MongoDB errno 111
问题描述
我有一台运行Ubuntu 12.04 LTS和MongoDB实例(服务正在运行并且可以在本地连接)的Linode服务器,我无法从外部来源连接到该服务器.
I have a Linode server running Ubuntu 12.04 LTS and MongoDB instance (service is running and CAN connect locally) that I can't connect to from an outside source.
我已将这两个规则添加到我的IP表中,其中< ip地址>是我要从其连接的服务器(如本 MongoDB参考):
I have added these two rules to my IP tables, where < ip address > is the server I want to connect FROM (as outlined in this MongoDB reference):
iptables -A INPUT -s < ip-address > -p tcp --destination-port 27017 -m state --state NEW,ESTABLISHED -j ACCEPT
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
iptables -A OUTPUT -d < ip-address > -p tcp --source-port 27017 -m state --state ESTABLISHED -j ACCEPT
我在IP表中看到了一条规则,该规则允许27017与<之间的连接. ip地址>,但是当我尝试从连接时,< ip address>使用以下命令进入我的mongo数据库:
And I see the rule in my IP table allowing connections on 27017 to and from < ip address > however when I try to connect from , < ip address > to my mongo database using a command like this:
mongo databasedomain/databasename -u username -p password
我收到此错误:
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
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 APPRECIATED!!!! Thanks!!!
推荐答案
感谢大家的帮助!
结果证明这是一个iptable冲突.有两个规则列出了端口打开状态(导致端口关闭).
Turns out that it was an iptable conflict. Two rules listing the port open (which resulted in a closed port).
但是,aka的一项评论和manu2013的另一项评论是我所遇到的问题,即使不是因为冲突.
However, one of the comments by aka and another by manu2013 were problems that I would have run into, if not for the conflict.
所以!始终记得编辑/etc/mongod.conf
文件并设置bind_ip = 0.0.0.0
以便与外部建立连接.
So! Always remember to edit the /etc/mongod.conf
file and set your bind_ip = 0.0.0.0
in order to make connections externally.
此外,请确保iptable中没有mongo想要的端口冲突规则(请参阅
Also, make sure that you don't have conflicting rules in your iptable for the port mongo wants (see link on mongodb's site to set up your iptables properly).
这篇关于与MongoDB errno 111的连接被拒绝的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!