无法连接到MongoDB / bizarre

时间:2011-05-19 11:08:00

标签: mongodb database-connection database

我通过官方教程http://www.mongodb.org/display/DOCS/Building+for+Linux

安装了mongoDB

守护进程启动,netstat-na | grep 27017显示:

tcp 0 0 0.0.0.0:27017 0.0.0.0: * LISTEN
unix 2 [ACC] STREAM LISTENING 100949 / tmp/mongodb-27017.sock

我添加了这些iptables规则:

-A INPUT-p tcp-m tcp - dport 27017-j ACCEPT
-A INPUT-p tcp-m tcp - dport 28017-j ACCEPT

通过浏览器加载时,我在28017的Web管理界面上表现良好

如果我在mongoHQ上添加远程连接,我可以使用数据库

通过利弊,如果我在本地运行客户端,则会引发错误:

Error: could not connect to server 127.0.0.1 shell / mongo.js: 79 except: connect failed

如果我尝试在现有项目上使用数据库,则无法连接到它。 我转过身,我不明白,提前感谢你的帮助。

2 个答案:

答案 0 :(得分:1)

解决方案如果您遇到此问题:

iptables -t filter -A OUTPUT -o lo -s 127.0.0.0/8 -d 127.0.0.0/8 -j ACCEPT
iptables -t filter -A INPUT  -i lo -s 127.0.0.0/8 -d 127.0.0.0/8 -j ACCEPT

没关系^^

答案 1 :(得分:0)

是否需要在端口27017上显式打开防火墙以允许出站TCP连接?

iptables -A OUTPUT -p tcp --dport 27017 -j ACCEPT