Linux systemd 常用命令


系統管理 systemctl

顯示系統狀態:
$ systemctl status

立即激活單元:
# systemctl start [單元]

立即停止單元:
# systemctl stop [單元]

重啟單元:
# systemctl restart [單元]

開機自動激活單元:
# systemctl enable [單元]

取消開機自動激活單元:
# systemctl disable [單元]

命令單元重新讀取配置:
# systemctl reload [單元]

輸出單元運行狀態:
$ systemctl status [單元]

檢查單元是否配置為自動啟動:
$ systemctl is-enabled [單元]

顯示單元的手冊頁:
# systemctl help [單元]

重新載入 systemd,掃描新的或有變動的單元:
# systemctl daemon-reload

輸出激活的單元:
$ systemctl list-units

查看已激活的服務:
$ systemctl list-units -t service

輸出運行失敗的單元:
$ systemctl --failed

禁用一個單元:
# systemctl mask [單元]

取消禁用一個單元:
# systemctl unmask [單元]

查看所有已安裝服務:
$ systemctl list-unit-files

檢查某個服務的所有配置細節
# systemctl show [服務]

獲取某個服務的依賴性列表
# systemctl list-dependencies [服務]

查看環境變量
$ systemctl show-environment

重啟系統
# systemctl reboot

關閉系統
# systemctl poweroff

進入待機狀態
# systemctl suspend

進入休眠狀態
# systemctl hibernate

進入混合休眠模式
# systemctl hybrid-sleep

進入救援狀態
# systemctl rescue

  

查看啟動耗時 systemd-analyze

查看啟動耗時
$ systemd-analyze

查看每個服務的啟動耗時
$ systemd-analyze blame

顯示瀑布狀的啟動過程流
$ systemd-analyze critical-chain

顯示指定服務的啟動流
$ systemd-analyze critical-chain [服務]

 

查看當前主機信息 hostnamectl

顯示當前主機的信息
$ hostnamectl

設置主機名。
# hostnamectl set-hostname [hostname]

 

本地化設置 localectl

查看本地化設置
$ localectl

設置本地化參數。
# localectl set-locale LANG=en_US.UTF-8
# localectl set-keymap en_US

 

時區設置 timedatectl

查看當前時區設置
$ timedatectl

列出所有可用時區
$ timedatectl list-timezones

設置當前時區
# timedatectl set-timezone Asia/Shanghai
# timedatectl set-time YYYY-MM-DD
# timedatectl set-time HH:MM:SS

設置硬件時間為本地時間
# timedatectl set-local-rtc true

 

查看用戶登錄信息 loginctl

列出當前所有會話
$ loginctl list-sessions

列出當前登錄用戶
$ loginctl list-users

查看指定用戶信息
$ loginctl show-user [username]

 

日志分析 journalctl

查看最近生成的5條日志
# journalctl -n 5

查看系統報錯 
# journalctl -p err

查看某個時間段生成的日志
# journalctl --since 時間("2017-08-01 00:00:00") --until"2017-08-02 02:30:00"

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM