首页 > 解决方案 > MongoDB绑定ip

问题描述

我想允许特定的 IP 地址与我在服务器中的 mongoDB 通信。为此,我打开mongod.conf并编辑如下:

net : 
  port: 27017
  bindIp: localhost,<IpAdres>
security:
  authorization: enable

我尝试了授权'enable',但唯一的等待是作为初始配置:

net : 
  port: 27017
  bindIp: localhost
#security:
# authorization: enable

如果我设置

net : 
  port: 27017, <IpAdress>
  bindIp: localhost
#security:
# authorization: enable

我得到的错误是:

Job for mongod.service failed because the control process exited with error code. See "systemctl status mongod.service" and "journalctl -xe" for details.

我的目标是只允许一组特定的 IP 地址与我服务器上的 mongo 通信(通信 = 进行咨询)

版本:4.0.18在 RedHat 7.8 上运行

netstat 看起来像这样

Proto | Recv-Q |Send-Q | Local Address | Foreign Address | State | PID/Program name

tcp | 0 | 0 |127.0.0.1:27017 | 0.0.0.0:* | LISTEN | -

标签: mongodb

解决方案


您不需要启用身份验证:

net:
 port: 27017
 bindIp: localhost, <YOUR_IP>

这是正确的,可能你有另一个通信问题,检查你的 ip/port 是否允许流量。

命令“ netstat -tulnp ”可以帮助您。

https://docs.mongodb.com/manual/reference/configuration-options/

无论如何,错误可能是由其他第三个原因引起的,请转到 /run/mongodb 文件夹并删除名为 mongod.pid 的文件。然后尝试使用以下命令重新启动 mongo:

   sudo service mongod restart 

推荐阅读