|
| 1 | +Systemd |
| 2 | +=== |
| 3 | + |
| 4 | +最常用的 [Systemd](https://systemd.io/) 命令备忘单快速参考 |
| 5 | + |
| 6 | +命令 |
| 7 | +---- |
| 8 | + |
| 9 | +### 查看系统信息 |
| 10 | + |
| 11 | +:- | - |
| 12 | +:- | - |
| 13 | +`systemctl list-dependencies` | 显示单元的依赖关系 |
| 14 | +`systemctl list-sockets` | 列出套接字和激活的内容 |
| 15 | +`systemctl list-jobs` | 查看活动的 systemd 作业 |
| 16 | +`systemctl list-unit-files` | 查看单元文件及其状态 |
| 17 | +`systemctl list-units` | 显示单位是否已加载/活动 |
| 18 | +`systemctl get-default` | 列出默认目标(如运行级别) |
| 19 | +<!--rehype:className=style-list--> |
| 20 | + |
| 21 | +### 使用服务 |
| 22 | +<!--rehype:wrap-class=row-span-2--> |
| 23 | + |
| 24 | +:- | - |
| 25 | +:- | - |
| 26 | +`systemctl stop service` | <red>停止</red>正在运行的服务 |
| 27 | +`systemctl start service` | 启动服务 |
| 28 | +`systemctl restart service` | 重新启动正在运行的服务 |
| 29 | +`systemctl reload service` | 重新加载服务中的所有配置文件 |
| 30 | +`systemctl daemon-reload` | 必须运行以重新加载更改的单元文件 |
| 31 | +`systemctl status` | service 查看服务是否正在运行/启用 |
| 32 | +`systemctl --failed` | 显示未能运行的服务 |
| 33 | +`systemctl reset-failed` | 将任何单位从失败状态重置 |
| 34 | +`systemctl enable service` | 使服务在启动时启动 |
| 35 | +`systemctl disable service` | 禁用服务 - 不会在启动时启动 |
| 36 | +`systemctl show service` | 显示服务(或其他单元)的属性 |
| 37 | +`systemctl edit service` | 创建片段以放入单元文件 |
| 38 | +`systemctl edit --full service` | 编辑整个单元文件以进行服务 |
| 39 | +`systemctl -H host status network` | 远程运行任何 systemctl 命令 |
| 40 | +<!--rehype:className=style-list--> |
| 41 | + |
| 42 | +### 改变系统状态 |
| 43 | + |
| 44 | +:- | - |
| 45 | +:- | - |
| 46 | +`systemctl reboot` | 重启系统(reboot.target) |
| 47 | +`systemctl poweroff` | 关闭系统(poweroff.target) |
| 48 | +`systemctl emergency` | 进入紧急模式(emergency.target) |
| 49 | +`systemctl default` | 返回默认目标(multi-user.target) |
| 50 | +<!--rehype:className=style-list--> |
| 51 | + |
| 52 | +### 查看日志消息 |
| 53 | + |
| 54 | +:- | - |
| 55 | +:- | - |
| 56 | +`journalctl` | 显示所有收集的日志消息 |
| 57 | +`journalctl -u network.service` | 查看网络服务消息 |
| 58 | +`journalctl -f` | 关注出现的消息 |
| 59 | +`journalctl -k` | 仅显示内核消息 |
| 60 | +<!--rehype:className=style-list--> |
| 61 | + |
| 62 | +另见 |
| 63 | +--- |
| 64 | + |
| 65 | +- [Systemd 官网](https://systemd.io/) _(systemd.io)_ |
| 66 | +- [Systemd Cheat Sheet](https://access.redhat.com/sites/default/files/attachments/12052018_systemd_6.pdf) _(access.redhat.com)_ |
0 commit comments