mongodb设置远程连接

本文主要介绍如何远程连接mongodb。

如果还没有安装mongodb可以参考如下文章:

https://blog.csdn.net/wild46cat/article/details/79455705

好,下面上货。

1、设置/etc/mongod.conf文件

mongodb在默认情况下是不允许远程连接的,需要在配置文件中进行配置

vim /etc/mongod.conf

注意里面的内容:

net:
  port: 27017
  bindIp: 127.0.0.1  # Listen to local interface only, comment to listen on all interfaces.

我们需要把这个bindIp修改成0.0.0.0,这样才能允许任何远程主机的访问。

修改后如下:

net:
  port: 27017
  bindIp: 0.0.0.0  # Listen to local interface only, comment to listen on all interfaces.

然后启动mongodb。

systemctl restart mongodb.service


2、关闭防火墙,或者允许27017对外访问。

一般情况下,这样就是OK的了,但是需要注意你的防火墙是否允许27017(或者你配置的端口)支持对外访问。

我们可以先暴力的关闭防火墙:

systemctl stop firewalld

3、测试连接

mongo 192.168.0.11:27017

如果配置的正确,那么就能够进入到mongoshell中。

猜你喜欢

转载自blog.csdn.net/wild46cat/article/details/79937194