在CentOS上为MongoDB设置安全措施主要包括以下几个方面:
/etc/mongod.conf
,在 security
部分设置 authorization: enabled
。sudo systemctl restart mongod
。mongo
shell连接到MongoDB。use admin
db.createUser({
user: "admin",
pwd: "your_strong_password",
roles: [ { role: "root", db: "admin" } ]
})
use your_database
db.createUser({
user: "your_username",
pwd: "your_password",
roles: [ { role: "readWrite", db: "your_database" } ]
})
/etc/mongod.conf
配置文件中添加 bindIp
参数,指定允许连接的IP地址或主机名。net: bindIp: 127.0.0.1
。/etc/mongod.conf
配置文件中添加以下参数:net:
ssl:
mode: requireSSL
PEMKeyFile: /path/to/mongodb-cert.pem
firewalld
)限制对MongoDB端口的访问。sudo firewall-cmd --zone=public --add-port=27017/tcp --permanent
sudo firewall-cmd --reload
以上步骤涵盖了在CentOS上为MongoDB设置基本的安全措施,确保数据库的安全性。请根据你的具体需求和环境调整配置。