This commit is contained in:
2021-11-14 15:52:46 +08:00
parent 915c231124
commit 1e344dc204
112 changed files with 1039 additions and 1039 deletions

View File

@@ -6,7 +6,7 @@ tags: ["systemd", "systemctl", "journalctl"]
categories: ["OS"]
---
# 系统资源(unit)分类
## 系统资源(unit)分类
Unit | 描述
---- | ----
Service | 系统服务,默认
@@ -22,7 +22,7 @@ Socket | 进程间通信的 socket
Swap | swap 文件
Timer | 定时器
# Target 与传统 runlevel 对应关系
## Target 与传统 runlevel 对应关系
传统运行等级 | 新版 target 命名 | 链接名
---- | ---- | ----
Runlevel 0 | runlevel0.target | poweroff.target
@@ -33,7 +33,7 @@ Runlevel 4 | runlevel4.target | multi-user.target
Runlevel 5 | runlevel5.target | graphical.target
Runlevel 6 | runlevel6.target | reboot.target
# systemctl 命令
## systemctl 命令
- 查看版本
```bash
systemctl --version
@@ -92,7 +92,7 @@ Runlevel 6 | runlevel6.target | reboot.target
systemctl daemon-reload
```
# systemd-analyze 命令
## systemd-analyze 命令
- 查看启动耗时
```bash
systemd-analyze
@@ -110,7 +110,7 @@ Runlevel 6 | runlevel6.target | reboot.target
systemd-analyze critical-chain atd.service
```
# journalctl 命令
## journalctl 命令
- 查看所有日志(默认只保存本次启动的日志)
```bash
journalctl
@@ -208,14 +208,14 @@ Runlevel 6 | runlevel6.target | reboot.target
journalctl --vacuum-time=1years
```
# 其他相似命令
## 其他相似命令
- hostnamectl
- localectl
- timedatectl
- loginctl
# Unit 配置文件
## [Unit]
## Unit 配置文件
### [Unit]
- Description: 简短描述
- Documentation: 文档地址
- Requires: 当前 Unit 依赖的其他 Unit如果它们没有运行当前 Unit 会启动失败
@@ -226,7 +226,7 @@ Runlevel 6 | runlevel6.target | reboot.target
- Conflicts: 这里指定的 Unit 不能与当前 Unit 同时运行
- Condition...: 当前 Unit 运行必须满足的条件,否则不会运行
- Assert...: 当前 Unit 运行必须满足的条件,否则会报启动失败
## [Service]
### [Service]
- WorkingDirectory: 设置进程的工作目录
- 特殊值 "~" 表示 User= 用户的家目录
- 设为一个以 RootDirectory= 为基准的绝对路径
@@ -271,13 +271,13 @@ Runlevel 6 | runlevel6.target | reboot.target
- on-watchdog: 超时退出,才会重启
- always: 不管是什么退出原因,总是重启
- RestartSec: 系统重启前等待的秒数
## [Install]
### [Install]
- WantedBy: 它的值是一个或多个 Target当前 Unit 激活时(enable)符号链接会放入/etc/systemd/system目录下面以 Target 名 + .wants 后缀构成的子目录中
- RequiredBy: 它的值是一个或多个 Target当前 Unit 激活时,符号链接会放入/etc/systemd/system目录下面以 Target 名 + .required 后缀构成的子目录中
- Alias: 当前 Unit 可用于启动的别名
- Also: 当前 Unit 激活(enable)时,会被同时激活的其他 Unit
# Unit 配置文件占位符
## Unit 配置文件占位符
占位符 | 作用 | 描述
---- | ---- | ----
%n | 完整的服务名称 |