以下是Debian下MongoDB的安全设置步骤:
安装MongoDB
更新系统并添加官方仓库,安装MongoDB:
sudo apt update && sudo apt install -y mongodb-org
启用身份验证
编辑配置文件 /etc/mongod.conf
,添加:
security:
authorization: enabled
重启服务:sudo systemctl restart mongod
。
创建管理员账户
进入MongoDB shell,切换到admin
数据库创建用户:
use admin
db.createUser({
user: "admin",
pwd: "强密码",
roles: [{ role: "userAdminAnyDatabase", db: "admin" }]
})
限制网络访问
net.bindIp: 127.0.0.1
。ufw
)限制端口访问:sudo ufw allow from 信任IP/32 to any port 27017
sudo ufw reload
加密通信(TLS/SSL)
net:
ssl:
mode: requireSSL
PEMKeyFile: /path/to/mongodb.pem
```。
权限管理与审计
readWrite
)。security:
auditLog:
destination: file
path: /var/log/mongodb/audit.json
```。
其他安全措施
net:
http:
enabled: false
```。
mongodump --out /备份路径
。sudo apt update && sudo apt upgrade
。参考来源: