最近開(kāi)始使用systemd,相比于以往使用service命令,或者直接修改/etc/init.d,或者chkconfig這樣多種工具搭配來(lái)完成一個(gè)系統(tǒng)服務(wù)的配置,部署,systemd的野心極大,它要讓一切都回歸統(tǒng)一,redhat系已經(jīng)將systemd作為了其默認(rèn)的系統(tǒng)服務(wù)管理工具。
這篇文章記錄了一些systemd常用的用法,大都是我自己會(huì)用到的。
-
啟動(dòng)級(jí)別配置
由于工作需要,常常會(huì)在虛擬機(jī)中安裝各類linux系統(tǒng),而絕大部分時(shí)間,我們需要的只是一個(gè)文字界面,能夠通過(guò)host ssh到VM中,圖形界面沒(méi)必要起著,白白浪費(fèi)cpu和內(nèi)存,通過(guò)systemctl命令配置默認(rèn)進(jìn)入文字界面,只需一行:
systemctl set-default multi-user.target
如果要切回圖形界面,相應(yīng)地:
systemctl set-default graphical.target
-
開(kāi)機(jī)啟動(dòng)服務(wù)
systemctl enable ***.service
-
停止開(kāi)機(jī)啟動(dòng)服務(wù)
systemctl disable ***.service
-
啟動(dòng)/停止/重啟服務(wù)
systemctl start/stop/restart ***.service
-
查詢服務(wù)狀態(tài)
systemctl status ***.service
-
在遠(yuǎn)程機(jī)器上執(zhí)行命令,類似ssh user@host ""
systemctl -H user@hostname
-
列出系統(tǒng)服務(wù),-t后用tab鍵可以關(guān)聯(lián)出所有支持的unit類型
systemctl -t service
-
列出所有已經(jīng)加載的units的狀態(tài)
systemctl -a
-
列出加載的units/sockets/timers
systemctl list-units [pattern]
systemctl list-sockets [pattern]
systemctl list-timers [pattern]
-
查詢某項(xiàng)服務(wù)是否active,以sshd.serice為例
systemctl is-active sshd.service
-
直接查看某項(xiàng)服務(wù)的配置文件,以sshd.serice為例
systemctl cat sshd.service
-
查看服務(wù)的依賴關(guān)系,以sshd.serice為例
systemctl list-dependencies sshd.service
-
查看環(huán)境變量
systemctl show-environment
systemctl 還能實(shí)習(xí)非常之多的系統(tǒng)管理配置功能,不在這一一列舉了。
|