簡體   English   中英

MongoDB副本集TLS / SSL

[英]MongoDB replicaset TLS/SSL

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

怎么了 我該如何解決?

我應該同時看到這兩個IP

當然是。

bindIp告訴mongodb服務監聽哪個系統網絡接口。 這些是本地系統接口,而不是客戶端。 一旦mongobd綁定到接口,任何地方的客戶端都可以連接到該IP:

  • 綁定到10.10.20.XXX:私有類網絡接口允許客戶端從同一網絡中的任何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連接,並允許對“報告”數據庫進行讀寫。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM