第 2 章 使用 systemctl管理系统服务
要管理系统级别服务,请使用 systemctl 工具。您可以通过启用控制服务和单元来与 systemd 交互。使用 systemctl,您可以管理系统服务的状态,列出可用的服务,并显示系统服务的状态。
2.1. 列出系统服务 复制链接链接已复制到粘贴板!
复制链接链接已复制到粘贴板!
要优化系统性能,您可以使用 systemctl 命令列出和查看系统服务。系统服务处理后台进程、管理硬件并支持核心系统功能。
先决条件
- 您有管理特权。
流程
列出所有当前载入的服务单元:
$ systemctl list-units --type serviceUNIT LOAD ACTIVE SUB DESCRIPTION abrt-ccpp.service loaded active exited Install ABRT coredump hook abrt-oops.service loaded active running ABRT kernel log watcher abrtd.service loaded active running Automated Bug Reporting Tool ... systemd-vconsole-setup.service loaded active exited Configure Virtual Console tog-pegasus.service loaded active running OpenPegasus CIM Server LOAD = Reflects whether the unit definition was properly loaded. ACTIVE = The high-level unit activation state, or a generalization of SUB. SUB = The low-level unit activation state, values depend on unit type. 46 loaded units listed. Pass --all to see loaded but inactive units, too. To show all installed unit files use 'systemctl list-unit-files'默认情况下,
systemctl list-units命令只显示活跃的单元。对于每个服务单元文件,命令提供以下参数的概述:UNIT- 服务单元的全名
LOAD- 配置文件的载入状态
ACTIVE或SUB- 当前高级别和低级别单元文件激活状态
DESCRIPTION- 单元目的和功能的简短描述
列出所有载入的单元,而不考虑它们的状态:
$ systemctl list-units --type service --all列出所有可用服务单元的状态,如
:启用或禁用$ systemctl list-unit-files --type serviceUNIT FILE STATE abrt-ccpp.service enabled abrt-oops.service enabled abrtd.service enabled ... wpa_supplicant.service disabled ypbind.service disabled 208 unit files listed.对于每个服务单元,这个命令会显示:
-
UNIT FILE:服务单元的全名。 -
STATE:服务单元是否已启用或禁用,以便在引导时自动启动的信息。
-