systemctl
重啟
systemctl reboot
關(guān)閉
systemctl poweroff
CPU停止工作
systemctl halt
暫停系統(tǒng)
systemctl suspend
休眠
systemctl hibernate
交互式休眠
systemctl hybrid-sleep
單用戶狀態(tài)
systemctl rescue
systemd-analyze
啟動(dòng)耗時(shí)
systemd-analyze
每個(gè)服務(wù)的啟動(dòng)耗時(shí)
systemd-analyze blame
瀑布狀的啟動(dòng)過程流
systemd-analyze critical-chain
顯示指定服務(wù)的啟動(dòng)流
systemd-analyze critical-chain atd.service
hostnamect
顯示當(dāng)前主機(jī)的信息
hostnamectl
設(shè)置主機(jī)名
hostnamectl set-hostname xxxx
localectl
查看本地化設(shè)置
localectl
設(shè)置本地化參數(shù)
localectl set-locale LANG=en_GB.utf8
localectl set-keymap en_GB
timedatectl
查看當(dāng)前時(shí)區(qū)設(shè)置
timedatectl
顯示所有可用的時(shí)區(qū)
timedatectl list-timezones
設(shè)置當(dāng)前時(shí)區(qū)
timedatectl set-timezone America/New_York
timedatectl set-time 2018-10-25
timedatectl set-time 11:32:00
loginctl
列出當(dāng)前session
loginctl list-sessions
列出當(dāng)前登錄用戶
loginctl list-users
列出顯示指定用戶的信息
loginctl show-user root
查詢狀態(tài)
列出正在運(yùn)行的 Unit
systemctl list-units
列出所有Unit钱贯,包括沒有找到配置文件的或者啟動(dòng)失敗的
systemctl list-units --all
列出所有沒有運(yùn)行的 Unit
systemctl list-units --all --state=inactive
列出所有加載失敗的 Unit
systemctl list-units --failed
列出所有正在運(yùn)行的议泵、類型為 service 的 Unit
systemctl list-units --type=service
查詢狀態(tài)
顯示系統(tǒng)狀態(tài)
systemctl status
顯示單個(gè) Unit 的狀態(tài)
systemctl status bluetooth.service
顯示遠(yuǎn)程主機(jī)的某個(gè) Unit 的狀態(tài)
systemctl -H root@rhel7.example.com status httpd.service
顯示某個(gè) Unit 是否正在運(yùn)行
systemctl is-active application.service
顯示某個(gè) Unit 是否處于啟動(dòng)失敗狀態(tài)
systemctl is-failed application.service
顯示某個(gè) Unit 服務(wù)是否建立了啟動(dòng)鏈接
systemctl is-enabled application.service
服務(wù)管理
立即啟動(dòng)一個(gè)服務(wù)
systemctl start apache.service
立即停止一個(gè)服務(wù)
systemctl stop apache.service
重啟一個(gè)服務(wù)
systemctl restart apache.service
殺死一個(gè)服務(wù)的所有子進(jìn)程
systemctl kill apache.service
重新加載一個(gè)服務(wù)的配置文件
systemctl reload apache.service
重載所有修改過的配置文件
systemctl daemon-reload
顯示某個(gè) Unit 的所有底層參數(shù)
systemctl show httpd.service
顯示某個(gè) Unit 的指定屬性的值
systemctl show -p CPUShares httpd.service
設(shè)置某個(gè) Unit 的指定屬性
systemctl set-property httpd.service CPUShares=500
列出一個(gè) Unit 的所有依賴
systemctl list-dependencies --all nginx.service
配置文件的狀態(tài)
列出所有配置文件
systemctl list-unit-files
列出指定類型的配置文件
systemctl list-unit-files --type=service
查看配置文件
systemctl cat atd.service
日志管理
查看所有日志(默認(rèn)情況下 糯崎,只保存本次啟動(dòng)的日志)
journalctl
查看內(nèi)核日志(不顯示應(yīng)用日志)
journalctl -k
查看系統(tǒng)本次啟動(dòng)的日志
journalctl -b
journalctl -b -0
查看上一次啟動(dòng)的日志(需更改設(shè)置)
$ sudo journalctl -b -1
查看指定時(shí)間的日志
journalctl --since="2012-10-30 18:17:16"
journalctl --since "20 min ago"
journalctl --since yesterday
journalctl --since "2015-01-10" --until "2015-01-11 03:00"
journalctl --since 09:00 --until "1 hour ago"
顯示尾部的最新10行日志
journalctl -n
顯示尾部指定行數(shù)的日志
journalctl -n 20
實(shí)時(shí)滾動(dòng)顯示最新日志
journalctl -f
查看指定服務(wù)的日志
journalctl /usr/lib/systemd/systemd
查看指定進(jìn)程的日志
journalctl _PID=1
查看某個(gè)路徑的腳本的日志
journalctl /usr/bin/bash
查看指定用戶的日志
journalctl _UID=33 --since today
查看某個(gè) Unit 的日志
journalctl -u nginx.service
journalctl -u nginx.service --since today
實(shí)時(shí)滾動(dòng)顯示某個(gè) Unit 的最新日志
journalctl -u nginx.service -f
合并顯示多個(gè) Unit 的日志
journalctl -u nginx.service -u php-fpm.service --since today
查看指定優(yōu)先級(及其以上級別)的日志侣滩,共有8級
0: emerg 1: alert 2: crit 3: err 4: warning 5: notice 6: info 7: debug
journalctl -p err -b
日志默認(rèn)分頁輸出,--no-pager 改為正常的標(biāo)準(zhǔn)輸出
journalctl --no-pager
以 JSON 格式(單行)輸出
journalctl -b -u nginx.service -o json
以 JSON 格式(多行)輸出,可讀性更好
journalctl -b -u nginx.service -o json-pretty
顯示日志占據(jù)的硬盤空間
$ sudo journalctl --disk-usage
指定日志文件占據(jù)的最大空間
$ sudo journalctl --vacuum-size=1G
指定日志文件保存多久
$ sudo journalctl --vacuum-time=1years