查询所有单元的状态:
[[email protected] ~]# systemctl UNIT LOAD ACTIVE SUB DESCRIPTION proc-sys-fs-binfmt_misc.automount loaded active waiting Arbitrary Executable File Formats File System Automoun sys-devices-pci00...get1:0:0-1:0:0:0-block-sr0.device loaded active plugged VBOX_CD-ROM sys-devices-pci0000:00-0000:00:03.0-net-enp0s3.device loaded active plugged PRO/1000 MT Desktop Adapter sys-devices-pci00...0-0000:00:05.0-sound-card0.device loaded active plugged 82801AA AC‘97 Audio Controller sys-devices-pci0000:00-0000:00:08.0-net-enp0s8.device loaded active plugged PRO/1000 MT Desktop Adapter sys-devices-pci00...0:0-2:0:0:0-block-sda-sda1.device loaded active plugged VBOX_HARDDISK sys-devices-pci00...0:0-2:0:0:0-block-sda-sda2.device loaded active plugged LVM PV ewUQqv-N1i5-9xcA-GRad-2BLV-qOTh-vNPOd2 on /dev/ sys-devices-pci00...get2:0:0-2:0:0:0-block-sda.device loaded active plugged VBOX_HARDDISK sys-devices-platform-serial8250-tty-ttyS0.device loaded active plugged /sys/devices/platform/serial8250/tty/ttyS0...
仅查询服务单元的状态:
[[email protected] ~]# systemctl --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 abrt-xorg.service loaded active running ABRT Xorg log watcher abrtd.service loaded active running ABRT Automated Bug Reporting Tool accounts-daemon.service loaded active running Accounts Service ...
查看处于失败或维护状态的任何单元:
[[email protected] ~]# systemctl status rngd.service -l rngd.service - Hardware RNG Entropy Gatherer Daemon Loaded: loaded (/usr/lib/systemd/system/rngd.service; enabled) Active: failed (Result: exit-code) since Fri 2015-07-17 11:08:27 CST; 32min ago Process: 649 ExecStart=/sbin/rngd -f (code=exited, status=1/FAILURE) Main PID: 649 (code=exited, status=1/FAILURE) CGroup: /system.slice/rngd.service Jul 17 11:08:25 rhce7.example.com systemd[1]: Started Hardware RNG Entropy Gatherer Daemon. Jul 17 11:08:27 rhce7.example.com rngd[649]: Unable to open file: /dev/tpm0 Jul 17 11:08:27 rhce7.example.com rngd[649]: can‘t open any entropy source Jul 17 11:08:27 rhce7.example.com rngd[649]: Maybe RNG device modules are not loaded Jul 17 11:08:27 rhce7.example.com systemd[1]: rngd.service: main process exited, code=exited, status=1/FAILURE Jul 17 11:08:27 rhce7.example.com systemd[1]: Unit rngd.service entered failed state. [[email protected] ~]#
查看特定单元是否活动:
[[email protected] ~]# systemctl is-active sshd active
查看特定单元是否已经开启自启动:
[[email protected] ~]# systemctl is-enabled sshd enabled
列出所有已经加载单元的活动状态
[[email protected] ~]# 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 abrt-xorg.service loaded active running ABRT Xorg log watcher abrtd.service loaded active running ABRT Automated Bug Reporting accounts-daemon.service loaded active running Accounts Service alsa-state.service loaded active running Manage Sound Card State (rest atd.service loaded active running Job spooling tools
查看所有单元的已启用和已禁用设置
[[email protected] ~]# systemctl list-unit-files --type=service UNIT FILE STATE abrt-ccpp.service enabled abrt-oops.service enabled abrt-pstoreoops.service disabled abrt-vmcore.service enabled abrt-xorg.service enabled abrtd.service enabled accounts-daemon.service enabled alsa-restore.service static
查看失败的服务的状态
[[email protected] ~]# systemctl list-unit-files --type=service UNIT FILE STATE abrt-ccpp.service enabled abrt-oops.service enabled abrt-pstoreoops.service disabled abrt-vmcore.service enabled abrt-xorg.service enabled abrtd.service enabled accounts-daemon.service enabled alsa-restore.service static
屏蔽服务
有时候可能安装了互相冲突的服务,比如network和NetworkManager,iptables和firewalld
可以将服务屏蔽。屏蔽将在配置目录中创建链接,使的启动该服务时不发生任何事
[[email protected] ~]# systemctl mask network ln -s ‘/dev/null‘ ‘/etc/systemd/system/network.service‘ [[email protected] ~]# systemctl unmask network rm ‘/etc/systemd/system/network.service‘
时间: 2024-10-25 12:16:18