【问题标题】:MongoDB replicaset TLS/SSLMongoDB 副本集 TLS/SSL
【发布时间】:2018-09-20 12:14:07
【问题描述】:

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

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

【问题讨论】:

  • 您能否确认两个接口都有效,即在实例上执行的ifconfig 显示 10.10.20.21 和 5.22.25.45 ?
  • 10.10.20.21 是私有 IP,如果这个集群实例和 5.22.25.45 是服务器的有效 IP 是我的应用程序在那里并且想要连接。我应该在这个 mongo 集群服务器的 ifconfig 中看到这两个 IP 吗?

标签: mongodb ssl replication replicaset


【解决方案1】:

我应该同时查看这两个 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 连接,并允许对“报告”数据库进行读写。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-04-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多