systemctl 启动、停止、重新加载、重启服务、列出服务单元、检查服务状态、启用/禁用服务、管理运行级别/电源管理。
一、使用systemctl 命令 管理服务 (Start/Stop/Status/Restart/Reload) 服务
格式: systemctl start [service-name]
service-name:服务名
** systemctl 启动 firewalld服务命令
[root@c7 ~]# systemctl start firewalld
(start 命令不输出任何内容)
** systemctl 停止 firewalld服务命令
[root@c7 ~]# systemctl stop firewalld
** systemctl 重启 firewalld 服务命令
[root@c7 ~]# systemctl restart firewalld
** systemctl 重新加载 firewalld 服务命令
[root@c7 ~]# systemctl reload firewalld
** systemctl 检查服务状态
[root@c7 ~]# systemctl status firewalld
** systemctl 检查服务是否设置为开机启动
[root@c7 ~]# systemctl enable httpd.service [root@c7 ~]# systemctl disable httpd.service
使用 is-enable 选项检查开机是否启动服务
[root@c7 ~]# systemctl is-enabled httpd.service disabled [root@c7 ~]# systemctl is-enabled firewalld disabled
enabled 表示开机启动该服务
disabled 表示开机时不启动该服务
systemctl 列出单元 (list-units)
[root@c7 ~]# systemctl list-units UNIT LOAD ACTIVE SUB DESCRIPTION proc-sys-fs-binfmt_misc.automount loaded active waiting Arbitrary Executable File Forma sys-devices-pci0000:00-0000:00:07.1-ata2-host2-target2:0:0-2:0:0:0-block-sr0.device loade sys-devices-pci0000:00-0000:00:10.0-host0-target0:0:0-0:0:0:0-block-sda-sda1.device loade sys-devices-pci0000:00-0000:00:10.0-host0-target0:0:0-0:0:0:0-block-sda-sda2.device loade sys-devices-pci0000:00-0000:00:10.0-host0-target0:0:0-0:0:0:0-block-sda.device loaded act sys-devices-pci0000:00-0000:00:11.0-0000:02:01.0-net-ens33.device loaded active plugged
列出所有活动的服务:
[root@c7 ~]# systemctl list-units -t service
查看系统中所有服务的开机启动状态:
[root@localhost cron]# 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
systemctl 重启、关机系统
关机:systemctl poweroff
重启: systemctl reboot
系统休眠:systemctl hibernate
使用systemctl 管理远程系统
# systemctl status httpd -H root@192.168.1.131
-H : 指定远程主机的用户名和密码