在CentOS上对MongoDB进行安全配置,可以遵循以下步骤:
启用身份验证:
/etc/mongod.conf
)。security
部分,并设置authorization
为enabled
。security:
authorization: enabled
创建管理员用户:
sudo systemctl start mongod
mongo
admin
数据库:use admin
db.createUser({
user: "admin",
pwd: "your_password",
roles: [{ role: "userAdminAnyDatabase", db: "admin" }, "readWriteAnyDatabase"]
})
配置访问控制:
mydatabase
数据库创建一个只读用户:use mydatabase
db.createUser({
user: "readonlyuser",
pwd: "readonlypassword",
roles: [{ role: "read", db: "mydatabase" }]
})
启用SSL/TLS加密:
net:
ssl:
mode: requireSSL
PEMKeyFile: /path/to/mongodb.pem
CAFile: /path/to/ca.pem
sudo systemctl restart mongod
配置防火墙:
firewalld
:sudo firewall-cmd --permanent --zone=public --add-port=27017/tcp
sudo firewall-cmd --reload
限制IP地址访问:
bindIp
选项限制可以连接到MongoDB服务器的IP地址:net:
bindIp: 127.0.0.1,192.168.1.100
定期更新和维护:
通过以上步骤,您可以在CentOS上对MongoDB进行基本的安全配置。根据您的具体需求,可能还需要进行其他高级配置,例如启用审计日志、配置复制集等。