以下是Ubuntu下MongoDB的故障排查步骤:
sudo systemctl status mongod
或sudo service mongod status
检查服务是否运行。/var/log/mongodb/mongod.log
,定位错误信息。/etc/mongod.conf
中dbPath
、logPath
、port
等配置是否正确,使用mongod --config /etc/mongod.conf --eval
测试语法。mongodb
,使用sudo chown -R mongodb:mongodb /data/db
设置权限。sudo netstat -tulnp | grep 27017
确认端口未被占用,必要时修改配置或停止冲突进程。free -h
、df -h
等命令检查内存、磁盘空间是否充足。mongostat
、mongotop
监控性能,或借助第三方工具(如Prometheus)分析慢查询。/var/lib/mongodb/mongod.lock
并尝试修复:sudo mongod -f /etc/mongod.conf --repair
。ufw
或iptables
)是否放行端口。sudo systemctl restart mongod
。