「笔记」Systemd 的基础
常用命令
systemctl
- 启动服务: systemctl start service
- 停止服务: systemctl stop service
- 重启服务: systemctl restart service
- 重载服务: systemctl reload service
- 禁止启动: systemctl mask service
- 查看状态: systemctl status service
- 开机自启: systemctl enable service
- 关闭自启: systemctl disable service
- 是否自启: systemctl is-enabled service
- 取消禁止: systemctl unmask service
- 是否激活: systemctl is-active service
- 查看依赖: systemctl list-dependencies service
- 查看所有: systemctl list-units
- 重载配置:systemctl daemon-reload
journalctl
- 查看日志: journalctl -u service
示例
1 | # 查看所有 frp 服务 |
配置文件位置
- 软件包配置位置:
/lib/systemd/system
/run/systemd/system
- 用户配置位置:
/etc/systemd/system
/usr/lib/systemd/system
配置文件
1 | [Unit] |
修改或添加
Unit
后需要重新载入配置systemctl daemon-reload
Unit 模板
使用 [email protected]
来建立一个模板
使用 systemctl start [email protected]
来启动一个实例
使用占位符来使用参数
占位符 | 作用 |
---|---|
%n | 完整的 Unit 文件名 |
%m | 实际运行节点的 Machine ID, 适合用来做 Etcd 路径的一部分,如:/machines/%m/units |
%b | 有点像 Machine ID,但这个值每次节点重启都会改变,称为 Boot ID |
%H | 运行节点的主机名 |
%p | 文件名 @ 之前的部分 |
%p | 文件名 @ 和 . 之间的部分 |
本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来自 粥盐籽!