systemctl
systemd 是 Linux 下的一款系統和服務管理器,兼容 SysV 和 LSB 的啓動腳本。systemd 的特性有:支持並行化任務;同時採用 socket 式與 D-Bus 總線式激活服務;按需啓動守護進程(daemon);利用 Linux 的 cgroups 監視進程;支持快照和系統恢復;維護掛載點和自動掛載點;各服務間基於依賴關係進行精密控制。
任務 | 舊指令 | 新指令 |
使某服務自動啓動 | chkconfig --level 3 httpd on | systemctl enable httpd.service |
使某服務不自動啓動 | chkconfig --level 3 httpd off | systemctl disable httpd.service |
檢查服務狀態 | service httpd status | systemctl status httpd.service (服務詳細信息) systemctl is-enabled httpd.service (僅顯示是否 Active) |
顯示所有已啓動的服務 | chkconfig --list | systemctl list -units --type=service |
啓動某服務 | service httpd start | systemctl start httpd.service |
停止某服務 | service httpd stop | systemctl stop httpd.service |
重啓某服務 | service httpd restart | systemctl restart httpd.service |
某服務重新加載配置文件 | service httpd reload | systemctl reload httpd.service |
# systemctl #輸出已激活單元 # systemctl list-units #輸出已激活單元 # systemctl --failed #輸出運行失敗的單元 # systemctl list-unit-files #查看所有已安裝服務 # systemctl start nginx #啓動nginx # systemctl stop nginx #停止nginx # systemctl restart nginx #重啓nginx # systemctl reload nginx #重新加載nginx配置 # systemctl status nginx #輸出nginx運行狀態 # systemctl is-enabled nginx #檢查nginx是否配置爲自動啓動 # systemctl enable nginx #開機自動啓動nginx # systemctl disable nginx #取消開機自動啓動nginx # systemctl help nginx #顯示nginx的手冊頁 # systemctl daemon-reload #重新載入 systemd,掃描新的或有變動的單元 # systemctl reboot #重啓 # systemctl poweroff #退出系統並停止電源 # systemctl suspend #待機 # systemctl hibernate #休眠 # systemctl hybrid-sleep #混合休眠模式(同時休眠到硬盤並待機 # systemctl isolate graphical.target #等價於telinit 3 或 telinit 5