在Debian上配置MongoDB數據加密,主要涉及到兩個層面:傳輸層加密和存儲層加密。以下是詳細的步驟指南:
生成SSL證書:
openssl req -newkey rsa:2048 -new -nodes -x509 -days 3650 -keyout mongodb-key.pem -out mongodb-cert.pem
配置MongoDB使用SSL:
/etc/mongod.conf
)。net:
ssl:
mode: requireSSL
PEMKeyFile: /path/to/mongodb-key.pem
CAFile: /path/to/mongodb-cert.pem
重啟MongoDB服務:
sudo systemctl restart mongod
MongoDB支持使用TDE(Transparent Data Encryption)來加密存儲的數據。以下是配置步驟:
啟用加密:
/etc/mongod.conf
)。security:
authorization: enabled
keyFile: /path/to/mongodb-keyfile
生成密鑰文件:
openssl rand -base64 756 > /path/to/mongodb-keyfile
chmod 400 /path/to/mongodb-keyfile
重啟MongoDB服務:
sudo systemctl restart mongod
啟用加密:
db.adminCommand({parameter: 1, encryptionKeyFile: "/path/to/mongodb-keyfile"})
檢查SSL連接:
mongo
客戶端連接到MongoDB,并指定SSL選項:mongo --ssl --sslCAFile /path/to/mongodb-cert.pem --sslPEMKeyFile /path/to/mongodb-key.pem
檢查加密狀態:
db.runCommand({getParameter: 1, encryptionCipherMode: 1})
通過以上步驟,你可以在Debian上配置MongoDB的傳輸層和存儲層加密,確保數據的安全性。