在 mongoDb 4.xx 中绑定多个 IP

car*_*619 11 configuration-files mongodb mongodb4.0

对于 mongoDB 4.0.3,无法在 bindIp 中添加多个 ip

以下配置适用于本地主机

net:
   port:27017
   bindIp:127.0.0.1
Run Code Online (Sandbox Code Playgroud)

以下是从其他 ip 登录的工作:

net:
       port:27017
       bindIp:0.0.0.0
Run Code Online (Sandbox Code Playgroud)

以下不起作用

   bindIp:127.0.0.1 10.0.0.10
   bindIp:127.0.0.1,10.0.0.10
   bindIp:"127.0.0.1,10.0.0.10"
   bindIp:"127.0.0.1 10.0.0.10"
   bindIp:[127.0.0.1,10.0.0.10]
   bindIp:[127.0.0.1, 10.0.0.10]
Run Code Online (Sandbox Code Playgroud)

除了 0.0.0.0 或 127.0.0.1 之外的任何 ip 都会为 bindIP 提供错误

如果我尝试以下操作:

bindIp:10.0.0.10
ERROR: child process failed, exited with error number 48
Run Code Online (Sandbox Code Playgroud)

这个MongoDB Doc没有帮助

任何帮助将不胜感激。

tec*_*ick 5

您链接的文档实际上确实有答案。如果你去这里,你会看到指示:

要绑定到多个地址,请输入以逗号分隔的值列表。

例子

本地主机,/tmp/mongod.sock

我在我的环境中应用了这个,可以看到 mongod 正在侦听本地和指定的 IP。

root@aqi-backup:~# netstat -pano | grep 27017
tcp        0      0 10.0.1.149:27017        0.0.0.0:*               LISTEN      12541/mongod         off (0.00/0/0)
tcp        0      0 127.0.0.1:27017         0.0.0.0:*               LISTEN      12541/mongod         off (0.00/0/0)
Run Code Online (Sandbox Code Playgroud)

这是我的 mongod.conf 文件(相关部分)。

# network interfaces
net:
  port: 27017
  bindIp: 127.0.0.1,10.0.1.149
Run Code Online (Sandbox Code Playgroud)

  • 我发现的一件事是,您无法绑定到未绑定到接口的 IP。如果您输入 IP 错误,mongod 服务将无法启动。 (2认同)

pau*_*aul 5

用 ; 我在 Mongo 4.2.2 版本中使用

 net:
   port: 27017
   bindIp: 127.0.0.1;10.0.1.149
Run Code Online (Sandbox Code Playgroud)