我一直在为 mongo bind IP 而苦苦挣扎,我觉得现在是时候寻求帮助了。我正在使用 hostonly 网络192.168.56.0/24
。我有 4 个盒子。3 个盒子用于 mongo 192.168.56.111,192.168.56.112,192.168.56.113
。一个盒子用于应用程序192.168.56.114
。
因此对于 mongo 绑定参数是:bind_ip =127.0.0.1,192.168.56.114,192.168.56.113,192.168.56.112,192.168.56.111,10.0.2.1
2015-08-22T12:35:44.547+0000 E NETWORK [initandlisten] listen(): bind() failed errno:99 Cannot assign requested address for socket: 192.168.56.114:27017
2015-08-22T12:35:44.553+0000 I JOURNAL [initandlisten] journal dir=/var/lib/mongodb/journal
2015-08-22T12:35:44.554+0000 I JOURNAL [initandlisten] recover : no journal files present, no recovery needed
2015-08-22T12:35:44.623+0000 I JOURNAL [durability] Durability thread started
2015-08-22T12:35:44.624+0000 I JOURNAL [journal writer] Journal writer thread started
2015-08-22T12:35:44.624+0000 I CONTROL [initandlisten] MongoDB starting : pid=3519 port=27017 dbpath=/var/lib/mongodb 64-bit host=vagrant-ubuntu-trusty-64
2015-08-22T12:35:44.625+0000 I CONTROL [initandlisten] db version v3.0.5
2015-08-22T12:35:44.625+0000 I CONTROL [initandlisten] git version: 8bc4ae20708dbb493cb09338d9e7be6698e4a3a3
2015-08-22T12:35:44.625+0000 I CONTROL [initandlisten] build info: Linux ip-10-183-35-50 3.13.0-24-generic #46-Ubuntu SMP Thu Apr 10 19:11:08 UTC 2014 x86_64 BOOST_LIB_VERSION=1_49
2015-08-22T12:35:44.625+0000 I CONTROL [initandlisten] allocator: tcmalloc
2015-08-22T12:35:44.626+0000 I CONTROL [initandlisten] options: { config: "/etc/mongod.conf", net: { bindIp: "127.0.0.1,192.168.56.114,192.168.56.113,192.168.56.112,192.168.56.111,10.0.2.15", port: 27017 }, storage: { dbPath: "/var/lib/mongodb" }, systemLog: { destination: "file", logAppend: true, path: "/var/log/mongodb/mongod.log" } }
2015-08-22T12:35:44.631+0000 I CONTROL [initandlisten] now exiting
2015-08-22T12:35:44.631+0000 I NETWORK [initandlisten] shutdown: going to close listening sockets...
2015-08-22T12:35:44.632+0000 I NETWORK [initandlisten] removing socket file: /tmp/mongodb-27017.sock
2015-08-22T12:35:44.632+0000 I NETWORK [initandlisten] shutdown: going to flush diaglog...
2015-08-22T12:35:44.632+0000 I NETWORK [initandlisten] shutdown: going to close sockets...
2015-08-22T12:35:44.632+0000 I STORAGE [initandlisten] shutdown: waiting for fs preallocator...
2015-08-22T12:35:44.632+0000 I STORAGE [initandlisten] shutdown: final commit...
2015-08-22T12:35:44.635+0000 I JOURNAL [initandlisten] journalCleanup...
2015-08-22T12:35:44.635+0000 I JOURNAL [initandlisten] removeJournalFiles
2015-08-22T12:35:44.636+0000 I JOURNAL [initandlisten] Terminating durability thread ...
2015-08-22T12:35:44.735+0000 I JOURNAL [journal writer] Journal writer thread stopped
2015-08-22T12:35:44.736+0000 I JOURNAL [durability] Durability thread stopped
2015-08-22T12:35:44.736+0000 I STORAGE [initandlisten] shutdown: closing all files...
2015-08-22T12:35:44.736+0000 I STORAGE [initandlisten] closeAllFiles() finished
2015-08-22T12:35:44.737+0000 I STORAGE [initandlisten] shutdown: removing fs lock...
2015-08-22T12:35:44.737+0000 I CONTROL [initandlisten] dbexit: rc: 48
我真的不明白其他 IP 有什么问题。除了环回、自己的 IP 和 0.0.0.0/0 之外,其他所有 IP 都无法启动 mongodb。
答案1
指令bind_ip
用于指定 IP 地址在同一个系统上MongoDB 监听连接,不是从中接收连接的 IP 地址。
设置此选项可配置 mongod 或 mongos 进程以绑定到此地址并侦听来自此地址上的应用程序的连接。您可以将 mongod 或 mongos 实例连接到任何接口;但是,如果您将该进程连接到可公开访问的接口,请实施适当的身份验证或防火墙限制以保护数据库的完整性。
因此它应该不存在(推荐),或者包含 127.0.0.1 以仅接受本地连接,或者本地网络接口的 IP 地址。
如果您想限制哪些 IP 地址可以连接到 MongoDB,则需要使用防火墙。