systemctl 常用命令

2021-09-25 21:21:20 字數 1768 閱讀 7997

最近開始使用systemd,相比於以往使用service命令,或者直接修改/etc/init.d,或者chkconfig這樣多種工具搭配來完成乙個系統服務的配置,部署,systemd的野心極大,它要讓一切都回歸統一,redhat系已經將systemd作為了其預設的系統服務管理工具。

這篇文章記錄了一些systemd常用的用法,大都是我自己會用到的。

啟動級別配置

由於工作需要,常常會在虛擬機器中安裝各類linux系統,而絕大部分時間,我們需要的只是乙個文字介面,能夠通過host ssh到vm中,圖形介面沒必要起著,白白浪費cpu和記憶體,通過systemctl命令配置預設進入文字介面,只需一行:

systemctl set-default multi-user.target

如果要切回圖形介面,相應地:

systemctl set-default graphical.target

開機啟動服務

systemctl enable ***.service

停止開機啟動服務

systemctl disable ***.service

啟動/停止/重啟服務

systemctl start/stop/restart ***.service

查詢服務狀態

systemctl status ***.service

在遠端機器上執行命令,類似ssh user@host ""

systemctl -h user@hostname

列出系統服務,-t後用tab鍵可以關聯出所有支援的unit型別

systemctl -t service

列出所有已經載入的units的狀態

systemctl -a

列出載入的units/sockets/timers

systemctl list-units [pattern]

systemctl list-sockets [pattern]

systemctl list-timers [pattern]

查詢某項服務是否active,以sshd.serice為例

systemctl is-active sshd.service

直接檢視某項服務的配置檔案,以sshd.serice為例

systemctl cat sshd.service

檢視服務的依賴關係,以sshd.serice為例

systemctl list-dependencies sshd.service

檢視環境變數

systemctl show-environment

systemctl 還能實習非常之多的系統管理配置功能,不在這一一枚舉了。

systemctl常用命令

linux中systemctl詳細理解及常用命令 停不掉的服務可用下面方法新增刪除服務 新增 sudo update rc.d 服務名 defaults 刪除 sudo update rc.d f 服務名 remove linux 服務管理兩種方式service和systemctl systemd是...

systemctl 常用命令備忘

列出所有服務 包括啟用的和禁用的 systemctl list unit files type service 檢視某個服務 systemctl list unit files type service grep nginx 啟動 重啟 停止 過載服務以及檢查服務 如 httpd.service 狀...

systemctl 常用命令總結

常用命令 systemctl start 服務名 立即開啟 systemctl stop 服務名 立即關閉 systemctl restart 服務名 重啟服務 systemctl status 服務名 輸出執行狀態 systemctl is enabled 服務名 檢查是否配置為自動自啟 syst...