1、systemctl是rhel 7 的服務管理工具中主要的工具,它融合之前service和chkconfig的功能于一體。可以使用它永久性或只在當前會話中啟用/禁用服務。
systemctl可以列出正在運行的服務狀態,如圖:
systemd-cgls以樹形列出正在運行的進程,它可以遞歸顯示控制組內容。如圖:
2、如何啟動/關閉、啟用/禁用服務?
啟動一個服務:systemctl start postfix.service
關閉一個服務:systemctl stop postfix.service
重啟一個服務:systemctl restart postfix.service
顯示一個服務的狀態:systemctl status postfix.service
在開機時啟用一個服務:systemctl enable postfix.service
在開機時禁用一個服務:systemctl disable postfix.service
查看服務是否開機啟動:systemctl is-enabled postfix.service
查看已啟動的服務列表:systemctl list-unit-files|grep enabled
查看啟動失敗的服務列表:systemctl --failed
ps:使用命令 systemctl is-enabled postfix.service 得到的值可以是enable、disable或static,這里的 static 它是指對應的 unit 文件中沒有定義[install]區域,因此無法配置為開機啟動服務。
說明:啟用服務就是在當前“runlevel”的配置文件目錄/etc/systemd/system/multi-user.target.wants/里,建立/usr/lib/systemd/system里面對應服務配置文件的軟鏈接;禁用服務就是刪除此軟鏈接,添加服務就是添加軟連接。如圖:
以上這篇淺談rhel 7中systemctl 的用法(替代service和chkconfig)就是小編分享給大家的全部內容了,希望能給大家一個參考,也希望大家多多支持服務器之家。