最近開始使用systemd,相比於以往使用service命令,或者直接修改/etc/init.d,或者chkconfig這樣多種工具搭配來完成一個系統服務的配置,部署,systemd的野心極大,它要讓一切都回歸統一,redhat系已經將systemd做爲了其默認的系統服務管理工具。html
這篇文章記錄了一些systemd經常使用的用法,大都是我本身會用到的。linux
啓動級別配置
因爲工做須要,經常會在虛擬機中安裝各種linux系統,而絕大部分時間,咱們須要的只是一個文字界面,可以經過host ssh到VM中,圖形界面不必起着,白白浪費cpu和內存,經過systemctl命令配置默認進入文字界面,只需一行:ssh
systemctl set-default multi-user.targetsocket
若是要切回圖形界面,相應地:工具
systemctl set-default graphical.target.net
開機啓動服務rest
systemctl enable ***.serviceorm
中止開機啓動服務htm
systemctl disable ***.serviceblog
啓動/中止/重啓服務
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 還能實習很是之多的系統管理配置功能,不在這一一列舉了。
關於systemd的背景,還有它在社區引發一些有意思的爭論,甚至致使了debian的分裂,能夠看看
why systemd?
upstart or systemd
Posittions forming in the Debian init system discuession