在CentOS上设置MongoDB的安全性是非常重要的,以下是一些基本步骤来增强MongoDB的安全性:
启用身份验证:
/etc/mongod.conf
。security
部分,并设置authorization
为enabled
。security:
authorization: enabled
sudo systemctl restart mongod
创建管理员用户:
mongo
shell连接到MongoDB实例。mongo
admin
数据库。use admin
db.createUser({
user: "admin",
pwd: "yourpassword",
roles: ["userAdminAnyDatabase", "dbAdminAnyDatabase", "readWriteAnyDatabase", "dbOwner"]
})
使用SSL/TLS加密连接:
/etc/mongod.conf
,添加SSL配置。net:
ssl:
mode: requireSSL
PEMKeyFile: /etc/ssl/mongodb.pem
CAFile: /etc/ssl/ca.pem
sudo systemctl restart mongod
限制网络访问:
/etc/mongod.conf
,限制IP地址访问。net:
bindIp: 127.0.0.1,192.168.1.100 # 只允许本地和特定IP访问
sudo systemctl restart mongod
启用审计日志:
/etc/mongod.conf
,启用审计日志。security:
auditLog:
destination: file
format: JSON
path: /var/log/mongodb/audit.json
sudo systemctl restart mongod
定期更新和打补丁:
yum
或dnf
等包管理工具更新MongoDB。sudo yum update mongodb-org
通过以上步骤,你可以显著提高CentOS上MongoDB的安全性。请根据你的具体需求和环境调整配置。