MongoDB 装完,配置,启动,在浏览器输入47.106.***.14:27017
一直加载中,
在mac shell 测试端口telnet 47.106.***.14 27017
,发现确实无法连接。
telnet: Unable to connect to remote host
(这里要吐槽一句,mac 10.13 没有telnet命令了,这么基础的 Unix 命令,苹果居然给移除了。只好装回来brew install telnet
)
接着确认一下配置文件mongod.conf
> cat /usr/local/mongodb/bin/mongod.conf
# 数据目录
dbpath=/usr/local/mongodb/data/db
# 日志目录
logpath=/usr/local/mongodb/logs/mongodb.log
# 端口
port=27017
# 以守护进程的方式启用,即在后台运行
fork=true
# 启用验证
auth=true
# 绑定访问IP
bind_ip=0.0.0.0
确实配置了bind_ip=0.0.0.0
发现开了防火墙,允许80等一些端口,没有27017,于是加上
# 查看防火墙
systemctl status firewalld
# 查看允许的端口
firewall-cmd --list-ports
# 开启允许27017端口
firewall-cmd --zone=public --permanent --add-port=27017/tcp; firewall-cmd --reload
浏览器再次输入47.106.***.14:27017
,还是不行
查了一圈,发现还需要在ESC实例中设置安全组,把27017端口开放,点击添加安全组规则
,配置如下
![](https://img.haomeiwen.com/i4940721/3d84f717847266b6.jpg)
这时在浏览器输入47.106.***.14:27017
,网页出现以下一行字,终于可以了!
It looks like you are trying to access MongoDB over HTTP on the native driver port.
网友评论