mongodb - 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 | -
解决方案
您不需要启用身份验证:
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
推荐阅读
- python - 格式化 AWS lambda 请求的 Python 错误
- hyperledger-fabric - 无法使用 Hyperledger Fabric 节点 SDK 让对等方加入频道
- python - Keras 加载模型
- c# - 在 Python 中模仿 C# 类
- scripting - 用于修改身份验证数据条目的 wsadmin 脚本/命令参数
- python - TypeError:“int”对象不可下标 - 尝试创建 csv 文件时
- typescript - 使用 Typescript 构建纯 Vue 组件的最佳方法是什么
- python - BeautifulSoup 从 Web 获取表格时返回 No Data Recorded
- django - Django 的计划任务
- python - 基于列比较合并两个熊猫数据框并跳过右侧的常见列