在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
SSL/TLS加密:
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
防火墙配置:
禁用不必要的接口:
mongod.conf
中禁用HTTP接口和REST API:net:
http:
enabled: false
RESTinterfaceEnabled: false
通过上述步骤,可以显著提高Debian上MongoDB的安全级别。务必定期更新和维护这些安全设置,以应对不断变化的安全威胁。