最常用的 Systemd 命令备忘单快速参考
| :- | - |
|---|---|
systemctl stop service | |
systemctl start service | 启动服务 |
systemctl restart service | 重新启动正在运行的服务 |
systemctl reload service | 重新加载服务中的所有配置文件 |
systemctl daemon-reload | 必须运行以重新加载更改的单元文件 |
systemctl status service | 查看服务是否正在运行/启用 |
systemctl --failed | 显示未能运行的服务 |
systemctl reset-failed | 将任何单位从失败状态重置 |
systemctl enable service | 使服务在启动时启动 |
systemctl disable service | 禁用服务 - 不会在启动时启动 |
systemctl show service | 显示服务(或其他单元)的属性 |
systemctl edit service | 创建片段以放入单元文件 |
systemctl edit --full service | 编辑整个单元文件以进行服务 |
systemctl -H host status network | 远程运行任何 systemctl 命令 |
| SysVinit | Systemd | 说明 |
|---|---|---|
service SERVICE_NAME start | systemctl start SERVICE_NAME | 用于启动服务(不重启持久) |
service SERVICE_NAME stop | systemctl stop SERVICE_NAME | 用于停止服务(不永久重启) |
service SERVICE_NAME restart | systemctl restart SERVICE_NAME | 用于停止然后启动服务 |
service SERVICE_NAME reload | systemctl reload SERVICE_NAME | 重新加载配置文件而不中断挂起的操作 |
service SERVICE_NAME condrestart | systemctl condrestart SERVICE_NAME | 如果服务已在运行,则重新启动 |
service SERVICE_NAME status | systemctl status SERVICE_NAME | 判断服务当前是否正在运行 |
chkconfig SERVICE_NAME on | systemctl enable SERVICE_NAME | 打开服务,以便在下次启动时启动,或其他触发器 |
chkconfig SERVICE_NAME off | systemctl disable SERVICE_NAME | 为下次重新启动或任何其他触发器关闭服务 |
chkconfig SERVICE_NAME | systemctl is-enabled SERVICE_NAME | 用于检查服务是否配置为在当前环境中启动 |
chkconfig –list | systemctl list-unit-files –type=service (or) ls /etc/systemd/system/*.wants/ | 打印一个服务表,列出每个配置的运行级别打开或关闭 |
chkconfig –list | grep 5:on | systemctl list-dependencies graphical.target | 打印启动到图形模式时将启动的服务表 |
chkconfig SERVICE_NAME –list | ls /etc/systemd/system/*.wants/SERVICE_NAME.service | 用于列出此服务配置为打开或关闭的级别 |
chkconfig SERVICE_NAME –add | systemctl daemon-reload | 在创建新服务文件或修改任何配置时使用 |
| SysVinit | Systemd | 说明 |
|---|---|---|
0 | runlevel0.target, poweroff.target | 停止系统 |
1, s, single | runlevel1.target, rescue.target | 单用户模式 |
2, 4 | runlevel2.target, runlevel4.target, multi-user.target | 用户定义/站点特定的运行级别。 默认情况下,与 3 相同 |
3 | runlevel3.target, multi-user.target | 多用户,非图形。 用户通常可以通过多个控制台或通过网络登录 |
5 | runlevel5.target, graphical.target | 多用户,图形。 通常具有运行级别 3 的所有服务以及图形登录 |
6 | runlevel6.target, reboot.target | 重启 |
emergency | emergency.target | 应急外壳 |