systemctl status:查看服务状态与日志
用一条命令查看 systemd 服务的加载/开机自启状态、运行状态、主进程 PID 以及最近的日志。
运行 systemctl status nginx,即可查看该单元是否加载、是否开机自启、是否正在运行、主 PID 以及最近的日志行。
01命令
命令
$ systemctl status nginx02作用说明
systemctl status 一次性回答三个问题:"Loaded" 显示单元文件是否已加载以及 enabled/disabled(即是否开机自启);"Active" 显示当前是否运行、运行了多久以及主进程 PID;最后一段是最新的 journal 日志。脚本中要注意:状态码 0 表示正在运行,非 0 表示未运行(未运行时为 3)。需要完整历史日志请使用 journalctl -u <单元名>。
03风险
04撤销
✓无需撤销——该命令不会改变持久状态。
05来源
- Ubuntu Manpage: systemctl - Control the systemd system and service manager依据: "status [PATTERN...|URL...] Show terse runtime status information about one or more units ... This function is intended to generate human-readable output ... along with the most recent log data."
- systemctl(1) — Arch Linux manual依据: "status [PATTERN...|URL...] — Show terse runtime status information about one or more units, followed by most recent log data from the journal."
最后验证: 2026-09-19 · 分类: 系统与设置