系统学习 学习路径总入口:先选领域,再建立模型,最后用故障演练验证

systemd 常用命令速查

常用命令

systemctl status app
systemctl start app
systemctl stop app
systemctl restart app
systemctl reload app
systemctl enable app
systemctl disable app
systemctl enable --now app
systemctl is-active app
systemctl is-enabled app
systemctl daemon-reload
systemctl list-units --failed
systemctl list-unit-files
systemctl cat app
systemctl edit app
systemctl show app
journalctl -u app -f
journalctl -u app --since '1 hour ago'
journalctl -p err -b
systemd-analyze blame
systemd-analyze critical-chain

场景速查

目的 命令
查看依赖 systemctl list-dependencies app
查看定时器 systemctl list-timers
查看 target systemctl get-default / set-default
重载单个 unit systemctl reload-or-restart app
临时屏蔽 systemctl mask app / unmask app
查看日志占用 journalctl --disk-usage
清理日志 journalctl --vacuum-size=500M
启动耗时 systemd-analyze blame

易错点

相关命令

参考链接

读完自测

合上页面,先回答,再展开对照。

  1. 修改 unit 文件后,为什么必须执行 daemon-reload?
  2. systemctl enable 和 systemctl start 有什么区别?
  3. 为什么 journalctl 的日志在重启后可能丢失?
答案
  1. 否则 systemd 仍会使用旧配置,改动不会生效。
  2. enable 只设置开机自启,不等于启动服务;只 start 则不会开机自启。enable --now 可以同时完成两者。
  3. 因为 journald 是否持久化取决于 Storage= 配置,未配置持久化时重启后可能丢失。
微信小程序码:扫码打开命令速查小程序

小程序版

微信扫码,随时查命令