基本操作

查看服务

  • 列出所有服务
    1
    systemctl list-units --type=service
  • 列出所有已启用的服务
    1
    systemctl list-unit-files --state=enabled

查看日志

  1. journalctl -u — 查看指定服务日志
  2. journalctl -xe — 检查最新日志,排查错误

额外技能

检查依赖

1
systemctl list-dependencies <service>

修改配置

  1. 配置文件位置通常是:
    1
    2
    /etc/systemd/system/
    /lib/systemd/system/
  2. 修改后:
    1
    sudo systemctl daemon-reload
  3. 重启服务使修改生效

其他管理器概览

虽说 systemd 完全是主流,但是还有其他管理器的使用:

SysV 管理器:

1
2
service <service> start|stop|restart|status
chkconfig <service> on|off

Upstart 管理器:

1
2
initctl list
initctl start|stop|restart <service>