MongoDB副本集TLS / SSL

时间:2018-09-20 12:14:08

标签: mongodb ssl replication replicaset

我已成功通过私有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

这有什么问题?我该如何解决?

1 个答案:

答案 0 :(得分:0)

  

我应该同时看到这两个IP

是的,当然。

bindIp告诉mongodb服务要监听的系统网络接口。这些是本地系统接口,而不是客户端。 mongobd绑定到接口后,任何地方的客户端都可以连接到该IP:

  • 绑定到10.10.20.XXX:私有类A网络接口允许客户端从同一网络中的任何10.XXX.XXX.XXX IP连接
  • 绑定到5.22.25.XXX:公共网络接口允许客户端从Internet上的任何位置进行连接。

如果要限制对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连接,并允许对“报告”数据库进行读写。