当前位置: 首页 > Linux > 正文

systemctl Command examples

Using the systemctl Command

The most important command for managing services on a RHEL 7 (systemd) system is the systemctl command. Here are some examples of the systemctl command (using the nfs-server service as an example) and a few other commands that you may find useful:

  • Checking service status: To check the status of a service (for example, nfs-server.service), type the following:
  • Stopping a service: To stop a service, use the stop option as follows:
  • Starting a service: To start a service, use the start option as follows:
  • Enabling a service: To enable a service so it starts automatically at boot time, type the following:
  • Disable a service: To disable a service so it doesn’t start automatically at boot time, type the following:
  • Listing dependencies: To see dependencies of a service, use the list-dependencies option, as follows:
  • listing units: To see all known units(see below section for more options)# systemctl list-units
    UNIT                                          LOAD   ACTIVE SUB       DESCRIPTION
    proc-sys-fs-binfmt_misc.automount             loaded active waiting   Arbitrary Executable File Formats File System
    sys-devices-pci0000:00-0000:00:08.0-net-net0.device loaded active plugged   MCP55 Ethernet
    sys-devices-pci0000:00-0000:00:09.0-net-net1.device loaded active plugged   MCP55 Ethernet
    sys-devices-pci0000:00-0000:00:0a.0-0000:02:00.0-host0-port\x2d0:0-end_device\x2d0:0-target0:0:0-0:0:0:0-block-sda-s
    sys-devices-pci0000:00-0000:00:0a.0-0000:02:00.0-host0-port\x2d0:0-end_device\x2d0:0-target0:0:0-0:0:0:0-block-sda-s
    sys-devices-pci0000:00-0000:00:0a.0-0000:02:00.0-host0-port\x2d0:0-end_device\x2d0:0-target0
  • Listing units in targets: To see what services and other units (service, mount, path, socket, and so on) are associated with a particular target, type the following:
  • List specific types of units: Use the following command to list specific types of units (in these examples, service and mount unit types):
  • Listing all units: To list all units installed on the system, along with their current states, type the following:
  • View service processes with systemd-cgtop: To view processes associated with a particular service (cgroup), you can use the systemd-cgtop command. Like the top command (which sorts processes by such things as CPU and memory usage), systemd-cgtop lists running processes based on their service (cgroup label). Once systemd-cgtop is running, you can press keys to sort by memory (m), CPU (c), task (t), path (p), or I/O load (i). Here is an example:
  • Recursively view cgroup contents: To output a recursive list of cgroup content, use the systemd-cgls command:
  • View journal (log) files: Using the journalctl command you can view messages from the systemd journal. Using different options you can select which group of messages to display. The journalctl command also supports tab completion to fill in fields for which to search. Here are some examples:

本文固定链接: http://t.yjsec.com/index.php/2018/03/02/415/ | 下一站

该日志由 admin 于2018年03月02日发表在 Linux 分类下, 你可以发表评论,并在保留原文地址及作者的情况下引用到你的网站或博客。
原创文章转载请注明: systemctl Command examples | 下一站

systemctl Command examples:等您坐沙发呢!

发表评论

快捷键:Ctrl+Enter