Ubuntu下MongoDB数据加密可通过以下方式实现:
openssl生成自签名证书或从CA获取有效证书。openssl req -newkey rsa:2048 -x509 -days 365 -nodes -out mongodb-cert.crt -keyout mongodb-cert.key
/etc/mongod.conf,启用SSL并指定证书路径。net:
ssl:
mode: requireSSL
PEMKeyFile: /path/to/mongodb-cert.key
CAFile: /path/to/mongodb-cert.crt # 可选,用于验证客户端证书
sudo systemctl restart mongod
sudo dd if=/dev/urandom of=/etc/mongodb-keyfile bs=512 count=1
sudo chmod 400 /etc/mongodb-keyfile
sudo chown mongodb:mongodb /etc/mongodb-keyfile
/etc/mongod.conf中启用加密。security:
enableEncryption: true
encryptionCipherMode: AES256-CBC
encryptionKeyFile: /etc/mongodb-keyfile
sudo systemctl restart mongod
/etc/mongod.conf中配置加密参数。mongo --eval "db.runCommand({ serverStatus: 1 })" | grep -i encryption
输出中应包含加密模式和密钥文件信息。参考来源: