Mongo 无法连接到远程实例

str*_*trz 4 mongodb

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

mongo 192.168.192.168:27017
Run Code Online (Sandbox Code Playgroud)

我收到一个错误

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
Run Code Online (Sandbox Code Playgroud)

看起来 mongo 不收听来自其他 ip 的连接?我在 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
Run Code Online (Sandbox Code Playgroud)

看起来像 mond 听

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)
Run Code Online (Sandbox Code Playgroud)

防火墙规则

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   
Run Code Online (Sandbox Code Playgroud)

更新 我的 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
Run Code Online (Sandbox Code Playgroud)

str*_*trz 7

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