mongodb远程连接问题

时间:2014-04-03 01:26:20

标签: linux mongodb amazon-web-services iptables

我花了几天时间尝试配置运行linux mongodb的环境而没有结果。该平台在AWS EC2上运行。

mongodb配置了auth=true注释,port=27017

我的问题是当我尝试远程连接(甚至是从同一台机器连接)时,我得到了:

-bash-4.1# mongo myIP:27017/mybd 
MongoDB shell version: 2.4.9
connecting to: myIP:27017/mybd
Wed Apr  2 20:57:28.250 Error: couldn't connect to server myIP:27017 at src/mongo/shell/mongo.js:147
exception: connect failed

但是如果我尝试使用localhost:

-bash-4.1# mongo localhost:27017/mybd 
MongoDB shell version: 2.4.9
connecting to: localhost:27017/mybd
> 

现在更多信息:

-bash-4.1# netstat -a
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address               Foreign Address             State      
tcp        0      0 *:27017                     *:*                         LISTEN      
tcp        0      0 *:28017                     *:*                         LISTEN      
tcp        0      0 *:ssh                       *:*                         LISTEN      
tcp        0      0 localhost:smtp              *:*                         LISTEN      
tcp        0     48 ip-10-187-41-156.ec2.in:ssh 186-79-194-159.baf.mo:55311 ESTABLISHED 
tcp        0      0 *:ssh                       *:*                         LISTEN


-bash-4.1# iptables -L -n
Chain INPUT (policy ACCEPT)
target     prot opt source               destination         
ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0           state NEW tcp dpt:27017 

Chain FORWARD (policy ACCEPT)
target     prot opt source               destination         

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination         
ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0           tcp spt:27017 state ESTABLISHED 

最后,我确保安全组是正确的。我用0.0.0.0/0从外面打开27017和28017。

1 个答案:

答案 0 :(得分:3)

编辑/etc/mongod.conf

bind_ip = 0.0.0.0

它,现在你可以连接到你的远程mongodb实例。