Linux系統(tǒng)中systemctl命令詳解
Linux Systemctl是一個(gè)系統(tǒng)管理守護(hù)進(jìn)程、工具和庫的集合,用于取代System V、service和chkconfig命令,初始進(jìn)程主要負(fù)責(zé)控制systemd系統(tǒng)和服務(wù)管理器。通過Systemctl –help可以看到該命令主要分為:查詢或發(fā)送控制命令給systemd服務(wù),管理單元服務(wù)的命令,服務(wù)文件的相關(guān)命令,任務(wù)、環(huán)境、快照相關(guān)命令,systemd服務(wù)的配置重載,系統(tǒng)開機(jī)關(guān)機(jī)相關(guān)的命令。
1. 列出所有可用單元
# systemctl list-unit-files
2. 列出所有運(yùn)行中單元
# systemctl list-units
3. 列出所有失敗單元
# systemctl –failed
4. 檢查某個(gè)單元(如 crond.service)是否啟用
# systemctl is-enabled crond.service
5. 列出所有服務(wù)
# systemctl list-unit-files –type=service
6. Linux中如何啟動、重啟、停止、重載服務(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í),終端不會輸出任何內(nèi)容,只有status命令可以打印輸出。
7. 如何激活服務(wù)并在開機(jī)時(shí)啟用或禁用服務(wù)(即系統(tǒng)啟動時(shí)自動啟動mysql.service服務(wù))
# systemctl is-active mysql.service # systemctl enable mysql.service # systemctl disable mysql.service
8. 如何屏蔽(讓它不能啟動)或顯示服務(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'
9. 使用systemctl命令殺死服務(wù)
# systemctl kill crond
10. 列出所有系統(tǒng)掛載點(diǎn)
# systemctl list-unit-files –type=mount
11. 掛載、卸載、重新掛載、重載系統(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
12. 在啟動時(shí)激活、啟用或禁用掛載點(diǎn)(系統(tǒng)啟動時(shí)自動掛載)
# systemctl is-active tmp.mount # systemctl enable tmp.mount # systemctl disable tmp.mount
13. 在Linux中屏蔽(讓它不能啟用)或可見掛載點(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'
14. 列出所有可用系統(tǒng)套接口
# systemctl list-unit-files –type=socket
15. 檢查某個(gè)服務(wù)的所有配置細(xì)節(jié)
# systemctl show mysql
16. 獲取某個(gè)服務(wù)(httpd)的依賴性列表
# systemctl list-dependencies httpd.service
17. 啟動救援模式
# systemctl rescue
18. 進(jìn)入緊急模式
# systemctl emergency
19. 列出當(dāng)前使用的運(yùn)行等級
# systemctl get-default
20. 啟動運(yùn)行等級5,即圖形模式
# systemctl isolate runlevel5.target
或
# systemctl isolate graphical.target
21. 啟動運(yùn)行等級3,即多用戶模式(命令行)
# systemctl isolate runlevel3.target
或
# systemctl isolate multiuser.target
22. 設(shè)置多用戶模式或圖形模式為默認(rèn)運(yùn)行等級
# systemctl set-default runlevel3.target # systemctl set-default runlevel5.target
23. 重啟、停止、掛起、休眠系統(tǒng)或使系統(tǒng)進(jìn)入混合睡眠
# systemctl reboot # systemctl halt # systemctl suspend # systemctl hibernate # systemctl hybrid-sleep
對于不知運(yùn)行等級為何物的人,說明如下。
Runlevel 0 : 關(guān)閉系統(tǒng)
Runlevel 1 : 救援,維護(hù)模式
Runlevel 3 : 多用戶,無圖形系統(tǒng)
Runlevel 4 : 多用戶,無圖形系統(tǒng)
Runlevel 5 : 多用戶,圖形化系統(tǒng)
Runlevel 6 : 關(guān)閉并重啟機(jī)器
相關(guān)文章
FreeBSD6.0Release+Squid+Socks5服務(wù)器架設(shè)筆記
FreeBSD6.0Release+Squid+Socks5服務(wù)器架設(shè)筆記...2007-05-05漂亮的國產(chǎn)Linux操作系統(tǒng)Open Desktop賞析
漂亮的國產(chǎn)Linux操作系統(tǒng)Open Desktop賞析...2006-10-10手動釋放Linux服務(wù)器內(nèi)存(具體操作步驟)
Linux服務(wù)器在發(fā)現(xiàn)內(nèi)存不足時(shí),會自動清理cached區(qū)域,釋放內(nèi)存,然后繼續(xù)增大cache,free繼續(xù)減少。其實(shí)手動降低內(nèi)存使用率的方法也就是圖一時(shí)之快而已2013-08-08深入探討:unix多進(jìn)程編程之wait()與waitpid()函數(shù)
本篇文章是對unix多進(jìn)程編程中的wait函數(shù)與waitpid函數(shù)的使用進(jìn)行了詳細(xì)的分析介紹,需要的朋友參考下2013-05-05