系统版本:
lsb_release -a No LSB modules are available. Distributor ID: Ubuntu Description: Ubuntu 16.04.2 LTS Release: 16.04 Codename: xenialMongoDB版本:
> db.version()
2.6.10
ps:使用yum安装的mongodb
1、查看网络端口情况,发现mongodb服务绑定中本地ip上
netstat -tunlp
(Not all processes could be identified, non-owned process info
will not be shown, you would have to be root to see it all.)
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 127.0.1.1:53 0.0.0.0:* LISTEN -
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN -
tcp 0 0 127.0.0.1:27017 0.0.0.0:* LISTEN -
tcp6 0 0 :::22 :::* LISTEN -
udp 0 0 0.0.0.0:60855 0.0.0.0:* -
udp 0 0 127.0.1.1:53 0.0.0.0:* -
udp 0 0 0.0.0.0:68 0.0.0.0:* -
udp 0 0 0.0.0.0:631 0.0.0.0:* -
udp 0 0 0.0.0.0:5353 0.0.0.0:* -
udp6 0 0 :::44164 :::* -
udp6 0 0 :::5353 :::* -
2、修改/etc/mongodb.con文件中mongodb绑定端口的ip,绑定到任何ip上:
bind_ip = 0.0.0.0
3、查看系统网络端口情况,mongodb服务监听的端口绑定中所有ip上,这样能够被内网的主机能够访问到
netstat -tunlp
(Not all processes could be identified, non-owned process info
will not be shown, you would have to be root to see it all.)
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 127.0.1.1:53 0.0.0.0:* LISTEN -
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN -
tcp 0 0 0.0.0.0:27017 0.0.0.0:* LISTEN -
tcp6 0 0 :::22 :::* LISTEN -
udp 0 0 0.0.0.0:60855 0.0.0.0:* -
udp 0 0 127.0.1.1:53 0.0.0.0:* -
udp 0 0 0.0.0.0:68 0.0.0.0:* -
udp 0 0 0.0.0.0:631 0.0.0.0:* -
udp 0 0 0.0.0.0:5353 0.0.0.0:* -
udp6 0 0 :::44164 :::* -
udp6 0 0 :::5353 :::* -
4、使用内网的另外一台ubuntu系统机子:
输入 curl 192.168.31.172:27017 ,返回It looks like you are trying to access MongoDB over HTTP on the native driver port.
说明连接成功
或者中浏览器地址栏中输入http://192.168.31.172:27017/,enter后,回复上面相同的内容。