CentOS7中systemctl命令詳解整理

來源:互聯網
上載者:User

CentOS7中systemctl命令詳解整理

Linux Systemctl是一個系統管理守護進程、工具和庫的集合,用於取代System V、service和chkconfig命令,初始進程主要負責控制systemd系統和服務管理員。通過Systemctl –help可以看到該命令主要分為:查詢或發送控制命令給systemd服務,嵌入式管理單元服務的命令,服務檔案的相關命令,任務、環境、快照相關命令,systemd服務的配置重載,系統開機關機相關的命令。

  1. 列出所有可用單元
systemctl list-unit-files
  • 1
  • 1
  1. 列出所有運行中單元
systemctl list-units
  • 1
  • 1
  1. 列出所有失敗單元
systemctl –failed
  • 1
  • 1
  1. 檢查某個單元(如 crond.service)是否啟用
 systemctl is-enabled crond.service
  • 1
  • 1
  1. 列出所有服務
systemctl list-unit-files –type=service
  • 1
  • 1
  1. Linux中如何啟動、重啟、停止、重載服務以及檢查服務(如 httpd.service)狀態
systemctl start httpd.servicesystemctl restart httpd.servicesystemctl stop httpd.servicesystemctl reload httpd.servicesystemctl status httpd.service
  • 1
  • 2
  • 3
  • 4
  • 5
  • 1
  • 2
  • 3
  • 4
  • 5

注意:當我們使用systemctl的start,restart,stop和reload命令時,終端不會輸出任何內容,只有status命令可以列印輸出。

  1. 如何啟用服務並在開機時啟用或禁用服務(即系統啟動時自動啟動mysql.service服務)
systemctl is-active mysql.servicesystemctl enable mysql.servicesystemctl disable mysql.service
  • 1
  • 2
  • 3
  • 1
  • 2
  • 3
  1. 如何屏蔽(讓它不能啟動)或顯示服務(如ntpdate.service)
systemctl mask ntpdate.serviceln -s /dev/null /etc/systemd/system/ntpdate.servicesystemctl unmask ntpdate.servicerm /etc/systemd/system/ntpdate.service
  • 1
  • 2
  • 3
  • 4
  • 1
  • 2
  • 3
  • 4
  1. 使用systemctl命令殺死服務
systemctl kill crond
  • 1
  • 1
  1. 列出所有系統掛載點

systemctl list-unit-files –type=mount 11. 掛載、卸載、重新掛載、重載系統掛載點並檢查系統中掛載點狀態

systemctl start tmp.mountsystemctl stop tmp.mountsystemctl restart tmp.mountsystemctl reload tmp.mountsystemctl status tmp.mount
  • 1
  • 2
  • 3
  • 4
  • 5
  • 1
  • 2
  • 3
  • 4
  • 5
  1. 在啟動時啟用、啟用或禁用掛載點(系統啟動時自動掛載)
systemctl is-active tmp.mountsystemctl enable tmp.mountsystemctl disable tmp.mount
  • 1
  • 2
  • 3
  • 1
  • 2
  • 3
  1. 在Linux中屏蔽(讓它不能啟用)或可見掛載點
systemctl mask tmp.mountln -s /dev/null /etc/systemd/system/tmp.mountsystemctl unmask tmp.mountrm /etc/systemd/system/tmp.mount
  • 1
  • 2
  • 3
  • 4
  • 1
  • 2
  • 3
  • 4
  1. 列出所有可用系統套介面
systemctl list-unit-files –type=socket
  • 1
  • 1
  1. 檢查某個服務的所有配置細節
systemctl show mysql
  • 1
  • 1
  1. 擷取某個服務(httpd)的依賴性列表
systemctl list-dependencies httpd.service
  • 1
  • 1
  1. 啟動救援模式
systemctl rescue
  • 1
  • 1
  1. 進入緊急模式
systemctl emergency
  • 1
  • 1
  1. 列出當前使用的運行等級
systemctl get-default
  • 1
  • 1
  1. 啟動運行等級5,即圖形模式
systemctl isolate runlevel5.target
  • 1
  • 1

或

systemctl isolate graphical.target
  • 1
  1. 啟動運行等級3,即多使用者模式(命令列)
systemctl isolate runlevel3.target

或

systemctl isolate multiuser.target
  1. 設定多使用者模式或圖形模式為預設運行等級
systemctl set-default runlevel3.targetsystemctl set-default runlevel5.target
  1. 重啟、停止、掛起、休眠系統或使系統進入交互式睡眠
systemctl rebootsystemctl haltsystemctl suspendsystemctl hibernatesystemctl hybrid-sleep

對於不知運行等級為何物的人,說明如下。

Runlevel 0 : 關閉系統Runlevel 1 : 救援,維護模式Runlevel 3 : 多使用者,無圖形系統Runlevel 4 : 多使用者,無圖形系統Runlevel 5 : 多使用者,圖形化系統Runlevel 6 : 關閉並重啟機器

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.