在Mongod版本3.6.5中的bindIp配置选项中使用多个IP地址时,无法运行MongoDB服务器

时间:2018-06-25 05:18:40

标签: mongodb

我试图在bindIp配置选项中使用多个IP地址,并且在保存配置更改后,mongodb服务器将无法启动。同样的事情在MongoDB 3.4版中也可以实现

以下是配置设置:

    # network interfaces
net:
  port: 36784
  bindIp: 127.0.0.1,10.0.0.226

这是EC2实例的私有IP地址10.0.0.226。

相同的配置类型在MongoDB的早期版本中更适用于v3.4

如果我将bindIp设置为0.0.0.0,那么它当然允许与所有IP地址的远程连接。

重新启动服务器后,出现以下错误:

    mongod.service - High-performance, schema-free document-oriented database
   Loaded: loaded (/lib/systemd/system/mongod.service; enabled; vendor preset: enabled)
   Active: failed (Result: exit-code) since Mon 2018-06-25 05:36:45 UTC; 15s ago
     Docs: https://docs.mongodb.org/manual
  Process: 1570 ExecStart=/usr/bin/mongod --config /etc/mongod.conf (code=exited, status=48)
 Main PID: 1570 (code=exited, status=48)

Jun 25 05:36:45 ip-10-0-1-69 systemd[1]: Stopped High-performance, schema-free document-oriented database.
Jun 25 05:36:45 ip-10-0-1-69 systemd[1]: Started High-performance, schema-free document-oriented database.
Jun 25 05:36:45 ip-10-0-1-69 systemd[1]: mongod.service: Main process exited, code=exited, status=48/n/a
Jun 25 05:36:45 ip-10-0-1-69 systemd[1]: mongod.service: Unit entered failed state.
Jun 25 05:36:45 ip-10-0-1-69 systemd[1]: mongod.service: Failed with result 'exit-code'.

以下是日志文件的内容:

    2018-06-25T05:07:38.842+0000 I CONTROL  [initandlisten] now exiting
2018-06-25T05:07:38.842+0000 I CONTROL  [initandlisten] shutting down with code:48
2018-06-25T05:13:43.192+0000 I CONTROL  [main] ***** SERVER RESTARTED *****
2018-06-25T05:13:43.201+0000 I CONTROL  [initandlisten] MongoDB starting : pid=1390 port=36784 dbpath=/var/lib/mongodb 64-bit host=ip-10-0-1-69
2018-06-25T05:13:43.201+0000 I CONTROL  [initandlisten] db version v3.6.5
2018-06-25T05:13:43.201+0000 I CONTROL  [initandlisten] git version: a20ecd3e3a174162052ff99913bc2ca9a839d618
2018-06-25T05:13:43.201+0000 I CONTROL  [initandlisten] OpenSSL version: OpenSSL 1.0.2g  1 Mar 2016
2018-06-25T05:13:43.201+0000 I CONTROL  [initandlisten] allocator: tcmalloc
2018-06-25T05:13:43.201+0000 I CONTROL  [initandlisten] modules: none
2018-06-25T05:13:43.201+0000 I CONTROL  [initandlisten] build environment:
2018-06-25T05:13:43.201+0000 I CONTROL  [initandlisten]     distmod: ubuntu1604
2018-06-25T05:13:43.201+0000 I CONTROL  [initandlisten]     distarch: x86_64
2018-06-25T05:13:43.201+0000 I CONTROL  [initandlisten]     target_arch: x86_64
2018-06-25T05:13:43.201+0000 I CONTROL  [initandlisten] options: { config: "/etc/mongod.conf", net: { bindIp: "127.0.0.1,10.0.0.226", port: 36784 }, processManagement: { timeZoneInfo: "/usr/share/zoneinfo" }, storage: { dbPath: "/var/lib/mongodb", journal: { enabled: true } }, systemLog: { destination: "file", logAppend: true, path: "/var/log/mongodb/mongod.log" } }
2018-06-25T05:13:43.201+0000 E STORAGE  [initandlisten] Failed to set up listener: SocketException: Cannot assign requested address
2018-06-25T05:13:43.201+0000 I CONTROL  [initandlisten] now exiting
2018-06-25T05:13:43.201+0000 I CONTROL  [initandlisten] shutting down with code:48

我已经查看过官方文档,但找不到任何弃用通知。

可能是什么问题?

谢谢

1 个答案:

答案 0 :(得分:1)

当我从日志中正确理解了这一行

2018-06-25T05:13:43.201+0000 I CONTROL  [initandlisten] MongoDB starting : pid=1390 port=36784 dbpath=/var/lib/mongodb 64-bit host=ip-10-0-1-69

主机的IP是10.0.1.69,而不是10.0.0.226。那可以解释这个错误。