確保Debian上MongoDB的數據安全性可以通過以下幾個關鍵步驟來實現:
/etc/mongod.conf,在 security 部分添加或確認以下行:security:
authorization: enabled
sudo systemctl restart mongod
mongo -u admin -p --authenticationDatabase admin
use admin
db.createUser({
user: "myUserAdmin",
pwd: "myStrongPassword",
roles: [
{ role: "userAdminAnyDatabase", db: "admin" }
]
})
bindIp 參數限制MongoDB實例只能從特定IP地址訪問。例如,只允許本機訪問:net:
port: 27017
bindIp: 127.0.0.1
mongod.conf 中配置:net:
ssl:
mode: requireSSL
PEMKeyFile: /path/to/mongodb.pem
sudo systemctl restart mongod
use mydatabase
db.createUser({
user: "myuser",
pwd: "mypassword",
roles: [
{ role: "readWrite", db: "mydatabase" }
]
})
mongod.conf 中配置審計日志:security:
auditLog:
destination: file
format: JSON
path: /var/log/mongodb/audit.json
sudo systemctl restart mongod
sudo ufw allow from trusted_ip_address/32 port 27017
sudo ufw reload
sudo apt update
sudo apt install -y mongodb-org
通過上述步驟,可以顯著提高Debian上MongoDB的安全級別。務必定期更新和維護這些安全設置,以應對不斷變化的安全威脅。