MongoDB副本集设置正在提供-SocketException:无法分配请求的地址

时间:2018-11-03 14:36:46

标签: mongodb

我正在尝试设置MongoDB replica set,并且在启动服务器时遇到以下错误。

MongoDB的版本为4.0.2,我正在尝试在Ubuntu 18.04上安装

2018-11-03T14:17:21.463+0000 I CONTROL  [initandlisten] allocator: tcmalloc
2018-11-03T14:17:21.463+0000 I CONTROL  [initandlisten] modules: none
2018-11-03T14:17:21.463+0000 I CONTROL  [initandlisten] build environment:
2018-11-03T14:17:21.463+0000 I CONTROL  [initandlisten]     distmod: ubuntu1804
2018-11-03T14:17:21.463+0000 I CONTROL  [initandlisten]     distarch: x86_64
2018-11-03T14:17:21.463+0000 I CONTROL  [initandlisten]     target_arch: x86_64
2018-11-03T14:17:21.463+0000 I CONTROL  [initandlisten] options: { config: "/etc/mongod.conf", net: { bindIp: "127.0.0.1,dbtwo.example.net,dbthree.example.net", port: 27017 }, processManagement: { timeZoneInfo: "/usr/share/zoneinfo" }, replication: { replSetName: "rs0" }, security: { keyFile: "/opt/mongo/key1" }, storage: { dbPath: "/var/lib/mongodb", journal: { enabled: true } }, systemLog: { destination: "file", logAppend: true, path: "/var/log/mongodb/mongod.log" } }
2018-11-03T14:17:21.477+0000 E STORAGE  [initandlisten] Failed to set up listener: SocketException: Cannot assign requested address
2018-11-03T14:17:21.477+0000 I CONTROL  [initandlisten] now exiting
2018-11-03T14:17:21.477+0000 I CONTROL  [initandlisten] shutting down with code:48

我该如何解决?

1 个答案:

答案 0 :(得分:2)

您需要使用运行mongodb的同一实例/ vm的ips或主机名设置绑定ip。

例如:

  • 在vm1上:bindIp:192.168.10.12
  • 在vm2上:bindIp:192.168.10.13
  • 在vm3上:bindIp:192.168.10.14

但是,请注意,将bindIp设置为127.0.0.1将仅绑定到本地回送ip,并且不能从在其他vm上运行的服务器访问。

您需要将它们与适当的内部ip或可解析的主机名绑定。