RHCE7 -- systemctl命令

Posted 王超元

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了RHCE7 -- systemctl命令相关的知识,希望对你有一定的参考价值。

查询所有单元的状态:

技术分享
[[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‘

 禁用服务

[[email protected] ~]# systemctl disable network
network.service is not a native service, redirecting to /sbin/chkconfig.
Executing /sbin/chkconfig network off
[[email protected] ~]# 

禁用服务和屏蔽服务的区别:

·禁用服务:服务不会再系统系统的时候自动启动,也不会被其它单元文件启动,但可以手动启动

·屏蔽服务:无法手动启动,也无法自启动

 




以上是关于RHCE7 -- systemctl命令的主要内容,如果未能解决你的问题,请参考以下文章

RHCE7.0答案之调整逻辑卷

红帽7.4(RHCE7.4)磁盘扩容详细步骤

RHCE7 第二十一篇 Linux计划任务

RHCE7 学习里程-1.配置IP,DNS

RHCE7 学习里程-4用户权限,简单进程管理

全面分析RHCE7(红帽认证工程师)考试题目之 ---Firewall(防火墙)篇