Ubuntu 14.04.3 LTS server
我已经在本地网络的machine1( ) 上安装了 mongo 。我还27017
按照这使用以下命令进行指导:
sudo iptables -A INPUT -p tcp --destination-port 27017 -m state --state NEW,ESTABLISHED -j ACCEPT
sudo iptables -A OUTPUT -p tcp --source-port 27017 -m state --state ESTABLISHED -j ACCEPT
现行规定为(iptables -L
):
Chain INPUT (policy ACCEPT)
target prot opt source destination
ACCEPT tcp -- anywhere anywhere tcp dpt:27017 state NEW,ESTABLISHED
Chain FORWARD (policy ACCEPT)
target prot opt source destination
Chain OUTPUT (policy ACCEPT)
target prot opt source destination
ACCEPT tcp -- anywhere anywhere tcp spt:27017 state ESTABLISHED
但是我无法从 machine2(在同一网络中)连接到该端口:
$ mongo --host 192.168.0.108
MongoDB shell version: 3.0.4
connecting to: 192.168.0.108:27017/test
2016-01-23T18:02:14.848+0530 W NETWORK Failed to connect to 192.168.0.108:27017, reason: errno:61 Connection refused
2016-01-23T18:02:14.850+0530 E QUERY Error: couldn't connect to server 192.168.0.108:27017 (192.168.0.108), connection attempt failed
at connect (src/mongo/shell/mongo.js:181:14)
at (connect):1:6 at src/mongo/shell/mongo.js:181
exception: connect failed
我还尝试检查端口是否打开:
$ nc -v 192.168.0.108 27017
nc: connectx to 192.168.0.108 port 27017 (tcp) failed: Connection refused
我不确定我遗漏了什么。一定是犯了一些愚蠢的错误,因为这是我第一次设置 mongo。请帮忙。
更多信息
Mongo 守护进程正在运行。我可以从同一台机器连接到 mongo,但不能从另一台机器连接到 mongo。守护进程正在运行:
$ service mongod status mongod start/running, process 31205
端口为 27017
$ sudo netstat -tulpn | grep 27017 tcp 0 0 127.0.0.1:27017 0.0.0.0:* LISTEN 31205/mongod
我将其更改
bind_ip
为0.0.0.0
(如某处所建议的那样)并重新启动了 mongo。仍然出现相同的错误。发行版信息:
$ cat /etc/*release DISTRIB_ID=Ubuntu DISTRIB_RELEASE=14.04 DISTRIB_CODENAME=trusty DISTRIB_DESCRIPTION="Ubuntu 14.04.3 LTS" NAME="Ubuntu" VERSION="14.04.3 LTS, Trusty Tahr" ID=ubuntu ID_LIKE=debian PRETTY_NAME="Ubuntu 14.04.3 LTS" VERSION_ID="14.04"
答案1
问题没有bindIp
改变。我这边重启 mongo 时出现了一些问题。
习惯应该是验证 bindIp 是否真正改变。(使用sudo netstat -tulpn | grep 27017
)
感谢steeldriver指出这一点。