我已成功通过私有IP在3台服务器上启动了MongoDB 4副本集。现在,我想绑定另一个IP,它需要启用TLS / SSL。
我已经创建了PEMKeyFile和CAFile并将这些文件复制到所有3台服务器上,并将以下代码添加到所有3台服务器的mongod.config文件中。
# network interfaces
net:
port: 27017
bindIp: 10.10.20.21,5.22.25.45 # example private ip and one example valid IP
ssl:
mode: requireSSL
PEMKeyFile: /opt/mongo/mongo.pem
PEMKeyPassword: MyPassword
CAFile : /opt/mongo/CA.pem
allowInvalidCertificates: true
allowInvalidHostnames: true
security:
keyFile: /opt/mongo/mongo-keyfile
我遇到错误
E STORAGE [initandlisten] Failed to set up listener: SocketException: Cannot assign requested address
I CONTROL [initandlisten] now exiting
I CONTROL [initandlisten] shutting down with code:48
这有什么问题?我该如何解决?
答案 0 :(得分:0)
我应该同时看到这两个IP
是的,当然。
bindIp
告诉mongodb服务要监听的系统网络接口。这些是本地系统接口,而不是客户端。 mongobd绑定到接口后,任何地方的客户端都可以连接到该IP:
如果要限制对mongodb的访问并仅允许从特定IP /网络进行连接,则需要启用身份验证并将限制应用于用户或组:https://docs.mongodb.com/manual/reference/method/db.createUser/#authentication-restrictions。
例如
use admin
db.createUser(
{
user: "remote-client",
pwd: "password",
roles: [ { role: "readWrite", db: "reporting" } ],
authenticationRestrictions: [ {
clientSource: ["5.22.25.45"]
} ]
}
)
仅允许mongo -u remote-client -p password
从IP 5.22.25.45连接,并允许对“报告”数据库进行读写。