关于mongodb远程访问问题

背景:在视频学习vue开发中使用到了mongodb这个数据库,视频中安装在本地也能经过mongo命令访问到本地数据库。在练习中将mongodb安装到了云服务器上,经过外网来访问这个mongodb的时候却超时了。尝试使用ping命令去访问服务器ip能ping通,在本地的window下使用telnet ip:port的时候却ping不一样vue

版本:
mongodb3.6社区版mongodb

搜索资料:shell

  • 防火墙限制了端口的访问
解决: 直接关闭防火墙
结果:不起做用
  • mongodb配置文件中指定访问的ip
解决: mongodb -help查看帮助选项,
发现--config --bind_ip --bing_ip_all, 能够从三者中配置ip地址,配置ip为0.0.0.0(全部ip都能访问)
结果:不起做用

通读官网资料:
mongodb3.6版本变动 中有下面的一段引用数据库

Previously, starting from MongoDB 2.6, only the binaries from the official MongoDB RPM (Red Hat, CentOS, Fedora Linux, and derivatives) and DEB (Debian, Ubuntu, and derivatives) packages bind to localhost by default.
When bound only to the localhost, these MongoDB 3.6 binaries can only accept connections from clients (including the mongo shell, other members in your deployment for replica sets and sharded clusters) that are running on the same machine. Remote clients cannot connect to the binaries bound only to localhost.
To override and bind to other ip addresses, you can use the net.bindIp configuration file setting or the --bind_ip command-line option to specify a list of ip addresses.
mongodb只绑定localhost,客户端只能经过localhost访问,若是想要经过外网来访问须要添加bind_ip,那么问题来了上面经过查看别人博客的时候也使用了bind_ip选项绑定了0.0.0.0 为何行不通? 这里精确到绑定ip为云服务器的ip
结果:不起做用,启动报错

使用ssl做为外部链接的认证安全

上面经过绑定bind_ip选项来启动mongod服务发现报错,这里须要配置ssl证书, 参考官网配置ssl证书,还须要配置客户端的ssl,参考 官网Client配置ssl,简单归纳就是:要想外网访问就须要配置bing_ip,要想bing_ip起做用就得配置ssl经过经过证书认证
结果:不起做用,mongo 启动报错

都干到这一步了放弃是不可能的,继续查资料服务器

安所有署MongoDB最佳实践,中描述:MongoDB集群之间以及从客户端链接到MongoDB实例的链接应该使用SSL。使用SSL对性能没有影响而且能够防范相似于man-in-the-middle的攻击。参见 配置SSL 以得到更多信息。 注意MongoDB社区版默认并不支持SSL。你能够选用MongoDB企业版(有SSL支持),或者从源码从新编译MongoDB并使用 —ssl 选项来得到SSL功能。

下载企业版ide

下载企业版要我注册是怎么回事? 内心有种不祥的预感,继续查资料, clipboard.png

不想折腾了,直接老老实实在window下安装个mongodb吧,先入门了再研究更深的性能

相关文章
相关标签/搜索