在CentOS上配置MongoDB的安全性是非常重要的,以下是一些基本步骤和建议:
启用身份验证:
/etc/mongod.conf。security部分,并设置authorization为enabled。security:
authorization: enabled
sudo systemctl restart mongod
创建管理员用户:
mongo
admin数据库。use admin
db.createUser({
user: "admin",
pwd: "yourpassword",
roles: [{ role: "userAdminAnyDatabase", db: "admin" }]
})
使用SSL/TLS加密连接:
/etc/mongod.conf,添加SSL配置。net:
ssl:
mode: requireSSL
PEMKeyFile: /etc/ssl/mongodb.pem
CAFile: /etc/ssl/ca.pem
sudo systemctl restart mongod
配置防火墙:
sudo firewall-cmd --permanent --zone=public --add-port=27017/tcp
sudo firewall-cmd --reload
限制IP访问:
/etc/mongod.conf,添加bindIp配置以限制访问IP。net:
bindIp: 127.0.0.1,your_server_ip
sudo systemctl restart mongod
定期更新和维护:
监控和日志:
通过以上步骤,你可以大大提高CentOS上MongoDB的安全性。记住,安全是一个持续的过程,需要定期审查和更新配置。