最直接有效的是用 systemctl status,适用于当前主流 Linux 发行版;它显示服务是否运行、进程ID、启动时间、最近日志及失败原因,Active: active (running)表示正常,inactive (dead)表示停止,failed表示启动失败。
查指定服务状态,最直接有效的是用 systemctl status,适用于当前主流 linux 发行版(如 centos 7+、ubuntu 16.04+、debian 8+ 等)。它不仅能告诉你“是否在跑”,还能看到进程 id、启动时间、最近日志,甚至失败原因。
用 systemctl status 查详细状态
这是首选命令,信息全面且可靠:
- 运行
systemctl status nginx(把nginx换成你要查的服务名,比如sshd、docker) - 重点关注
Active:行:显示active (running)表示正常运行;inactive (dead)表示已停止;failed表示启动失败 - 底部几行是最近的日志,对排查配置错误、端口占用、权限问题特别有用
- 加
-l参数可查看完整日志:systemctl status nginx -l - 加
--no-pager避免分页,适合快速扫读:systemctl status nginx --no-pager
用 systemctl is-active 快速判断是否运行
适合脚本或需要简洁输出的场景:
直播话术巡检系统(Windows版) — 实时语音转写、关键词检测、场景自动切换、告警推送、大屏可视化。支持 Windows VB-Cable 虚拟声卡音频采集,阿里云 ASR 实时识别。一键启动脚本,自动安装环境。
-
systemctl is-active nginx只返回一行结果,如active或inactive - 注意:它只反映 systemd 记录的“激活状态”,不保证服务真正可用(例如主进程活着但子进程崩溃了)
- 配合 shell 判断更实用:
if [[ $(systemctl is-active nginx) == "active" ]]; then echo "OK"; fi
辅助验证:看进程和端口是否真在工作
systemctl 显示 active 不等于服务健康,建议交叉验证:
- 查进程是否存在:
ps aux | grep -v grep | grep nginx(排除 grep 自身) - 查监听端口:
ss -tuln | grep ':80'(比如 Nginx 默认监听 80,确认端口确实在用) - 查错误日志:
journalctl -u nginx --since "1 hour ago" -n 20(看近一小时最后 20 行)
老系统兼容:SysVinit 环境下用 service
CentOS 6、Debian 7 等旧系统仍用 SysVinit,命令略有不同:
-
service nginx status或/etc/init.d/nginx status - 部分系统支持
service --status-all | grep nginx,但输出格式较混乱,不推荐作为主要手段 - 这类系统通常没有 journalctl,可用
tail -n 20 /var/log/nginx/error.log查错
ps -p 1 -o comm= 确认初始化系统——输出 systemd 就走 systemctl 路线;输出 init 则大概率是 SysVinit。

















