Debian MongoDB網絡配置要點如下:
/etc/mongod.conf
中net.bindIp
參數,設置為0.0.0.0
允許所有IP連接(不安全,僅限測試環境),或指定受信任的局域網IP。ufw
或iptables
開放MongoDB端口,限制僅受信任網絡訪問,例如:sudo ufw allow 27017/tcp # 允許TCP 27017端口
sudo iptables -A INPUT -p tcp --dport 27017 -s 192.168.1.0/24 -j ACCEPT # 僅允許指定網段
security.authorization: enabled
,并創建具有權限的用戶。bindIp
指定內部IP。net.ssl.mode=requireSSL
。配置后需重啟服務:sudo systemctl restart mongod
,并使用mongo
客戶端驗證連接。