MongoDB 在 Debian 上的网络配置注意事项
一 基础网络与端口
net:
port: 27017
bindIp: 192.168.1.10,127.0.0.1
变更后执行:sudo systemctl restart mongod 使配置生效。二 安全加固
security:
authorization: enabled
net:
ssl:
mode: requireSSL
PEMKeyFile: /path/to/mongodb.pem
CAFile: /path/to/ca.pem
sudo ufw allow 27017/tcp;示例(iptables):仅放行内网段:sudo iptables -A INPUT -p tcp --dport 27017 -s 192.168.1.0/24 -j ACCEPT
sudo iptables -A INPUT -p tcp --dport 27017 -j DROP
security:
auditLog:
destination: file
format: JSON
path: /var/log/mongodb/audit.log
三 高可用与副本集网络
四 连接与排障
sudo systemctl status mongod;远程连通性可用 telnet your_server_ip 27017 或 nc -vz your_server_ip 27017 测试。mongodb://myUser:myPassword@your_server_ip:27017/myDatabase
应用侧需使用支持认证的驱动版本,避免因驱动过旧导致握手或认证失败。五 性能与资源控制