Linux Systemctl是一個(gè)系統(tǒng)管理守護(hù)進(jìn)程音念、工具和庫(kù)的集合昂勉,用于取代System V另伍、service和chkconfig命令敲街,初始進(jìn)程主要負(fù)責(zé)控制systemd系統(tǒng)和服務(wù)管理器团搞。通過(guò)Systemctl –help可以看到該命令主要分為:查詢(xún)或發(fā)送控制命令給systemd服務(wù),管理單元服務(wù)的命令多艇,服務(wù)文件的相關(guān)命令逻恐,任務(wù)、環(huán)境峻黍、快照相關(guān)命令复隆,systemd服務(wù)的配置重載,系統(tǒng)開(kāi)機(jī)關(guān)機(jī)相關(guān)的命令姆涩。
-
列出所有可用單元
systemctl list-unit-files
-
列出所有運(yùn)行中單元
systemctl list-units
-
列出所有失敗單元
systemctl –failed
-
檢查某個(gè)單元(如 crond.service)是否啟用
systemctl is-enabled crond.service
-
列出所有服務(wù)
systemctl list-unit-files –type=service
-
Linux中如何啟動(dòng)昏名、重啟、停止阵面、重載服務(wù)以及檢查服務(wù)(如 httpd.service)狀態(tài)
systemctl start httpd.service systemctl restart httpd.service systemctl stop httpd.service systemctl reload httpd.service systemctl status httpd.service
注意:當(dāng)我們使用systemctl的start,restart洪鸭,stop和reload命令時(shí)样刷,終端不會(huì)輸出任何內(nèi)容,只有status命令可以打印輸出览爵。
-
如何激活服務(wù)并在開(kāi)機(jī)時(shí)啟用或禁用服務(wù)(即系統(tǒng)啟動(dòng)時(shí)自動(dòng)啟動(dòng)mysql.service服務(wù))
systemctl is-active mysql.service systemctl enable mysql.service systemctl disable mysql.service
-
如何屏蔽(讓它不能啟動(dòng))或顯示服務(wù)(如ntpdate.service)
systemctl mask ntpdate.service ln -s /dev/null /etc/systemd/system/ntpdate.service systemctl unmask ntpdate.service rm /etc/systemd/system/ntpdate.service
-
使用systemctl命令殺死服務(wù)
systemctl kill crond
-
列出所有系統(tǒng)掛載點(diǎn)
systemctl list-unit-files –type=mount
-
掛載置鼻、卸載、重新掛載蜓竹、重載系統(tǒng)掛載點(diǎn)并檢查系統(tǒng)中掛載點(diǎn)狀態(tài)
systemctl start tmp.mount systemctl stop tmp.mount systemctl restart tmp.mount systemctl reload tmp.mount systemctl status tmp.mount
-
在啟動(dòng)時(shí)激活箕母、啟用或禁用掛載點(diǎn)(系統(tǒng)啟動(dòng)時(shí)自動(dòng)掛載)
systemctl is-active tmp.mount systemctl enable tmp.mount systemctl disable tmp.mount
-
在Linux中屏蔽(讓它不能啟用)或可見(jiàn)掛載點(diǎn)
systemctl mask tmp.mount ln -s /dev/null /etc/systemd/system/tmp.mount systemctl unmask tmp.mount rm /etc/systemd/system/tmp.mount
-
列出所有可用系統(tǒng)套接口
systemctl list-unit-files –type=socket
-
檢查某個(gè)服務(wù)的所有配置細(xì)節(jié)
systemctl show mysql
-
獲取某個(gè)服務(wù)(httpd)的依賴(lài)性列表
systemctl list-dependencies httpd.service
-
啟動(dòng)救援模式
systemctl rescue
-
進(jìn)入緊急模式
systemctl emergency
-
列出當(dāng)前使用的運(yùn)行等級(jí)
systemctl get-default
-
啟動(dòng)運(yùn)行等級(jí)5,即圖形模式
systemctl isolate runlevel5.target
或
systemctl isolate graphical.target
-
啟動(dòng)運(yùn)行等級(jí)3俱济,即多用戶(hù)模式(命令行)
systemctl isolate runlevel3.target
或
systemctl isolate multiuser.target
-
設(shè)置多用戶(hù)模式或圖形模式為默認(rèn)運(yùn)行等級(jí)
systemctl set-default runlevel3.target systemctl set-default runlevel5.target
-
重啟嘶是、停止、掛起蛛碌、休眠系統(tǒng)或使系統(tǒng)進(jìn)入混合睡眠
systemctl reboot systemctl halt systemctl suspend systemctl hibernate systemctl hybrid-sleep
對(duì)于不知運(yùn)行等級(jí)為何物的人聂喇,說(shuō)明如下。
Runlevel 0 : 關(guān)閉系統(tǒng)
Runlevel 1 : 救援蔚携,維護(hù)模式
Runlevel 3 : 多用戶(hù)希太,無(wú)圖形系統(tǒng)
Runlevel 4 : 多用戶(hù),無(wú)圖形系統(tǒng)
Runlevel 5 : 多用戶(hù)酝蜒,圖形化系統(tǒng)
Runlevel 6 : 關(guān)閉并重啟機(jī)器