Linux服務管理之系統管理員需要掌握的命令

來源:互聯網
上載者:User

標籤:

systemd的主要命令列工具是systemctl。大多數Linux系統管理員應該都已經非常熟悉系統服務和init系統管理,比如service,chkconfig和telinit命令的使用。systemd也完成同樣的管理工作,只是命令工具systemctl的文法有所不同而已。

1. sysvinit和systemd的命令對比列表

下表協助系統管理員瞭解systemd中可以取代原先sysvinit工作流程的命令。注意:service和chkconfig這兩個命令在systemd環境下依然可用。這裡以sshd服務為例:

sysvinit命令                 
systemd命令                   
備忘 
service sshd start
systemctl start sshd.service
用來啟動一個服務(並不會重啟現有的服務)
service sshd stop
systemctl stop sshd.service
用來停止一個服務(並不會重啟現有的服務)
service sshd restart
systemctl restart sshd.service
用來停止並啟動一個服務
service sshd reload
systemctl reload sshd.service
當支援時,重新裝載設定檔而不中斷等待操作
service sshd condrestart
systemctl condrestart sshd.service
如果服務正在運行,那麼重啟它
service sshd status
systemctl status sshd.service
彙報服務是否正在運行
ls /etc/rc.d/init.d/
systemctl list-unit-files --type=service
ls /lib/systemd/system/*.service
/etc/systemd/system/*.service
用來列出可以啟動或停止的服務列表
chkconfig sshd on
systemctl enable sshd.service
在下次啟動時或滿足其他觸發條件時設定服務為啟動
chkconfig sshd off
systemctl disable sshd.service
在下次啟動時或滿足其他觸發條件時設定服務為禁用
chkconfig sshd
systemctl is-enabled sshd.service
用來檢查一個服務在當前環境下被配置為啟用還是禁用
chkconfig --list
systemctl list-unit-files --type=service(推薦)
ls /etc/systemd/system/*.service
輸出在各個運行層級下服務的啟用和禁用情況
chkconfig sshd --list
ls /etc/systemd/system/*.wants/sshd.service
用來列出該服務在哪些運行層級下啟用和禁用
chkconfig sshd --add
systemctl daemon-reload
當建立新服務檔案或者變更設定時使用

注意:以上列出的所有/sbin/service 和 /sbin/chkconfig 在systemd環境下依然可以工作,並且在必要的情況下將會被翻譯成原生的等效命令。唯一的例外是 chkconfig --list。

sysvinit 和 systemd 改變運行層級命令對比表:

sysvinit命令                
systemd命令                      
備忘
telinit 3
systemctl isolate multi-user.target
或者
systemctl isolate runlevel3.target OR telinit 3
改變至多使用者運行層級
sed s/^id:.*:initdefault:/id:3:initdefault:/
ln -sf /lib/systemd/system/multi-user.target /etc/systemd/system/default.target
設定在下一次啟動時使用多使用者運行層級

sysvinit 和 systemd 電源管理命令對比表:

sysvinit命令                                            
systemd命令           
操作
reboot
systemctl reboot
重啟機器
halt -p
systemctl poweroff
關機
echo standby > /sys/power/statc
systemctl suspend
待機
echo platform > /sys/power/dist; echo dist > /sys/power/state    
或者
echo shutdown > /sys/power/disk;echo dist > /sys/power/state
systemctl hibernate
休眠

systemctl hybrid-sleep
混合睡眠模式(同時休眠到硬碟並待機)

關機命令不是每個登入使用者在任何情況下都可以執行的,一般只有管理員才可以關機。

2. systemctl命令執行個體

2.1 systemctl的基本用法

  • systemctl——列出所有已載入的單元及其狀態(單元是任務/服務的術語)。

  • systemctl list-units——列出所有單元。

  • systemctl start [NAME...]——啟動(啟用)一個或多個單元。

  • systemctl stop [NAME...]——停止(停用)一個或多個單元。

  • systemctl disable [NAME...]——禁用一個或多個單元檔案。

  • systemctl list-unit-files——顯示所有已安裝的單元檔案及其狀態。

  • systemctl --failed——顯示啟動過程中哪些單元出現故障。

  • systemctl --type=xxx——類型過濾器;類型可能是:服務,掛載點,裝置,通訊端和啟動目標。

  • systemctl enable debug-shell.service——啟動TTY 9上的shell,用於調試。

Linux服務管理之系統管理員需要掌握的命令

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.