要使用systemctl status查看服务状态,执行命令systemctl status 服务名,例如systemctl status nginx;输出中包含服务状态、主进程id、子进程信息及日志片段;关键信息包括active(运行状态)、loaded(配置加载情况)、main pid(主进程)和cgroup(相关进程组);若服务异常,可结合systemctl is-enabled检查开机自启状态,journalctl -u查看详细日志,sudo systemctl restart尝试重启服务,或检查对应配置文件;其他技巧如systemctl list-unit-files | grep 服务名查看开机启动项,systemctl list-units --type=service --state=running查看正在运行的服务。

在Linux系统中,使用systemctl status命令可以快速查看系统服务的状态信息。它不仅能告诉你某个服务当前是运行还是停止状态,还能提供最近的日志片段、主进程状态等关键信息,非常适合排查服务异常问题。

systemctl status 查看服务状态基本用法非常简单:

systemctl status 服务名
比如你想查看nginx服务的运行状态:
systemctl status nginx
执行后会输出类似以下内容:

● nginx.service - A high performance web server
Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)
Active: active (running) since Tue 2024-06-18 10:30:45 UTC; 2h ago
Main PID: 1234 (nginx)
Tasks: 2 (limit: 4915)
CGroup: /system.slice/nginx.service
├─1234 nginx: master process /usr/sbin/nginx -g daemon on; master_process on;
└─1235 nginx: worker process从输出可以看到服务是否正在运行(active)、启动时间、PID、以及子进程情况等。
systemctl status 的输出虽然看起来有点复杂,但几个关键部分要看得懂:
active (running) 或 inactive (dead)。(enabled) 表示开机自启。如果服务没启动,或者处于“failed”状态,通常还会显示错误日志片段,帮助定位问题。
当你发现某个服务状态不正常时,可以从以下几个方面入手:
检查服务是否被禁用:
systemctl is-enabled 服务名
查看完整日志:journalctl -u 服务名 可以看到更详细的日志记录。
尝试重启服务看看是否恢复:
sudo systemctl restart 服务名
如果服务无法启动,检查其配置文件是否正确:
不同服务配置位置不同,例如nginx的配置在 /etc/nginx/ 下。
快速查看某个服务是否开机自启:
systemctl list-unit-files | grep 服务名
查看所有正在运行的服务:
systemctl list-units --type=service --state=running
如果终端输出太多,可以用管道配合 less 查看:
systemctl status nginx | less
基本上就这些常见用法和注意事项了。掌握好systemctl status,能帮你快速判断服务是否正常运行,也能为后续排错打下基础。
以上就是如何查看Linux系统服务状态 systemctl status用法解析的详细内容,更多请关注php中文网其它相关文章!
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号