在 Debian 系统上查看 MongoDB 状态,常见有下面几种方式,按使用场景从“最常用”到“更底层”说明。
systemctl status mongod
或(老版本可能叫 mongodb):
systemctl status mongodb
说明:
active (running) → 正在运行inactive (dead) → 已停止failed → 启动失败(下面会讲排查)sudo systemctl start mongod
sudo systemctl stop mongod
sudo systemctl restart mongod
sudo systemctl enable mongod
ss -lntp | grep mongod
或
netstat -lntp | grep mongod
默认端口:
27017
mongosh
(老版本是 mongo)
db.runCommand({ serverStatus: 1 })
或更简单地看基本信息:
db.stats()
db.serverStatus().connections
MongoDB 日志位置(常见):
/var/log/mongodb/mongod.log
查看最近日志:
sudo tail -n 50 /var/log/mongodb/mongod.log
systemctl 找不到服务可能原因:
检查进程:
ps aux | grep mongod
✅ 最常用的一句:
systemctl status mongod
如果你愿意,可以告诉我:
我可以帮你精确排查。