第 2 章 使用 systemctl管理系统服务


要管理系统级别服务,请使用 systemctl 工具。您可以通过启用控制服务和单元来与 systemd 交互。使用 systemctl,您可以管理系统服务的状态,列出可用的服务,并显示系统服务的状态。

2.1. 列出系统服务

要优化系统性能,您可以使用 systemctl 命令列出和查看系统服务。系统服务处理后台进程、管理硬件并支持核心系统功能。

先决条件

  • 您有管理特权。

流程

  • 列出所有当前载入的服务单元:

    $ systemctl list-units --type service
    UNIT                             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
    配置文件的载入状态
    ACTIVESUB
    当前高级别和低级别单元文件激活状态
    DESCRIPTION
    单元目的和功能的简短描述
  • 列出所有载入的单元,而不考虑它们的状态:

    $ systemctl list-units --type service --all
  • 列出所有可用服务单元的状态,如 启用或禁用

    $ systemctl list-unit-files --type service
    UNIT 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:服务单元是否已启用或禁用,以便在引导时自动启动的信息。
Red Hat logoGithubredditYoutubeTwitter

学习

尝试、购买和销售

社区

關於紅帽

我们提供强化的解决方案,使企业能够更轻松地跨平台和环境(从核心数据中心到网络边缘)工作。

让开源更具包容性

红帽致力于替换我们的代码、文档和 Web 属性中存在问题的语言。欲了解更多详情,请参阅红帽博客.

关于红帽文档

Legal Notice

Theme

© 2026 Red Hat
返回顶部