MongoDB 在 Debian 的网络配置实操
一 核心配置文件与关键参数
二 允许远程访问的标准步骤
net:
port: 27017
bindIp: 127.0.0.1,192.168.1.10
如需临时全网监听(不推荐生产):bindIp: 0.0.0.0。三 安全加固必做项
use admin
db.createUser({
user: "admin",
pwd: "YourStrongP@ssw0rd",
roles: [ { role: "root", db: "admin" } ]
})
openssl req -newkey rsa:2048 -new -x509 -days 365 -nodes \
-out mongodb-cert.crt -keyout mongodb-cert.key
cat mongodb-cert.key mongodb-cert.crt > mongodb.pem
net:
ssl:
mode: requireSSL
PEMKeyFile: /path/to/mongodb.pem
CAFile: /path/to/ca.pem
四 副本集的网络配置要点
replication:
replSetName: rs0
net:
port: 27017
bindIp: 192.168.1.10,192.168.1.11,192.168.1.12
rs.initiate({
_id: "rs0",
members: [
{ _id: 0, host: "192.168.1.10:27017" },
{ _id: 1, host: "192.168.1.11:27017" },
{ _id: 2, host: "192.168.1.12:27017" }
]
})
五 常见问题快速排查