Mongodb
將 MongoDB 綁定到 IPv4 以及 IPv6
Mongo v. 3.4
配置文件的相應部分:
#network interfaces net: port: 27017 bindIp: 127.0.0.1,192.168.0.15,2001:db8:0:0:0:0:2:1 (IPs are made up)
無論我使用什麼格式:
- $$ 2001:db8:0:0:0:0:2:1 $$
- $$ 2001:db8:0:0:0:0:2:1%eth1 $$
我總是得到:
2017-05-17T09:54:54.358 I CONTROL [initandlisten] options: { config: "/etc/mongod.conf", net: { bindIp: "127.0.0.1,192.168.0.15,2001:db8:0:0:0:0:2:1", port: 27017 }, processManagement: { fork: true, pidFilePath: "/var/run/mongod.pid" }, storage: { dbPath: "/var/lib/mongo", journal: { enabled: true } }, systemLog: { destination: "file", logAppend: true, path: "/var/log/mongo/mongod.log" } } 2017-05-17T09:54:54.384 I NETWORK [initandlisten] getaddrinfo("2001:db8:0:0:0:0:2:1") failed: Address family for hostname not supported 2017-05-17T09:54:54.385 E NETWORK [initandlisten] listen(): socket is invalid. 2017-05-17T09:54:54.385 E NETWORK [initandlisten] Failed to set up sockets during startup. 2017-05-17T09:54:54.385 E STORAGE [initandlisten] Failed to set up listener: InternalError: Failed to set up sockets 2017-05-17T09:54:54.385 I NETWORK [initandlisten] shutdown: going to close listening sockets... 2017-05-17T09:54:54.385 I NETWORK [initandlisten] removing socket file: /tmp/mongodb-27017.sock 2017-05-17T09:54:54.385 I NETWORK [initandlisten] shutdown: going to flush diaglog... 2017-05-17T09:54:54.385 I CONTROL [initandlisten] now exiting 2017-05-17T09:54:54.385 I CONTROL [initandlisten] shutting down with code:48
如何正確綁定 Mongo 以偵聽 IPv6 地址?請注意,這是 3.4 版,不再需要 net.ipv6。
你找到答案了嗎?如果沒有,這裡是解決方案:
預設情況下禁用 IPv6,您必須啟用它才能在 IPv6 上綁定。以下網路配置應該可以工作:
net: ipv6: true port: 27017 bindIp: 127.0.0.1,192.168.0.15,2001:db8:0:0:0:0:2:1 (IPs are made up)
根據 MongoDB BOL Here 要綁定到所有
IPv4
地址,請輸入0.0.0.0
.要綁定到所有 IPv4 和 IPv6 地址,請輸入
0.0.0.0,::
或使用net.bindIpAll設置。**注意:**在綁定其他 IP 地址之前,請考慮啟用安全清單中列出的訪問控制和其他安全措施,以防止未經授權的訪問。
例如所有 IPv4 地址
#network interfaces net: port: 27017 bindIp: 0.0.0.0
例如所有 IPv4 和 IPv6 地址
#network interfaces net: port: 27017 bindIp: 0.0.0.0,:: Or net: port: 27017 bindIpAll: true
注意:-
net.bindIp
和net.bindIpAll
是互斥的。也就是說,您可以指定其中之一,但不能同時指定兩者。