Mongo无法连接到远程实例

时间:2014-12-27 21:24:53

标签: mongodb

我通过vagrant在远程服务器上安装了mongodb。我可以从我的本地系统访问postgres但mongo不可用。当我通过ssh登录并检查mongo状态时,它表示mongo正在运行,我也可以进行查询。当我尝试使用此命令从本地系统连接时:

mongo 192.168.192.168:27017

我收到错误

MongoDB shell version: 2.6.5
connecting to: 192.168.192.168:27017/test
2014-12-27T22:19:19.417+0100 warning: Failed to connect to 192.168.192.168:27017, reason: errno:111 Connection refused
2014-12-27T22:19:19.418+0100 Error: couldn't connect to server 192.168.192.168:27017 (192.168.192.168), connection attempt failed at src/mongo/shell/mongo.js:148
exception: connect failed

看起来像mongo不听其他ips的连接?我在mongo设置中评论了bind_ip,但它没有帮助。

通过nmap命令为192.168.192.168提供服务:

PORT     STATE SERVICE
22/tcp   open  ssh
80/tcp   open  http
111/tcp  open  rpcbind
5432/tcp open  postgresql
9000/tcp open  cslistener

看起来像mongd listen

sudo lsof -iTCP -sTCP:LISTEN | grep mongo
mongod    1988     mongodb    6u  IPv4   5407      0t0  TCP *:27017 (LISTEN)
mongod    1988     mongodb    8u  IPv4   5411      0t0  TCP *:28017 (LISTEN)

防火墙规则

sudo iptables -L -n
Chain INPUT (policy ACCEPT)
target     prot opt source               destination         

Chain FORWARD (policy ACCEPT)
target     prot opt source               destination         

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination   

更新 我的mongo配置

dbpath=/var/lib/mongodb

#where to log
logpath=/var/log/mongodb/mongodb.log

logappend=true

#bind_ip = 127.0.0.1
#port = 27017

# Enable journaling, http://www.mongodb.org/display/DOCS/Journaling
journal=true

# Enables periodic logging of CPU utilization and I/O wait
#cpu = true

# Turn on/off security.  Off is currently the default
#noauth = true
#auth = true

1 个答案:

答案 0 :(得分:4)

解决方案是更改mongo配置 bind_ip = 0.0.0.0