系統管理
|
systemctl
|
重啓系統
sudo systemctl reboot
暫停系統
sudo systemctl suspend
CPU 中止工做
sudo systemctl halt
關閉系統,切斷電源
sudo systemctl poweroff
|
systemd-analyze
|
查看啓動耗時
systemd-analyze
查看每一個服務啓動耗時
systemd-analyze blame
查看啓動過程流
systemd-analyze critical-chain
查看指定服務的啓動流
systemd-analyze critical-chain sshd.service
|
|
hostnamectl
|
查看當前主機信息
hostnamectl
設置主機名
sudo hostnamectl set-hostname ***
|
|
localectl
|
查看本地化設置
localectl
|
|
timedatectl
|
查看當前時區設置
timedatectl
顯示全部可用時區
timedatectl list-timezones
設置當前時區
sudo timedatectl set-timezone Africa/Juba
|
|
Unit
|
systemctl list-units
|
查看系統正在運行的單元
systemctl list-units
列出系統中全部單元
systemctl list-units --all
列出全部加載失敗的單元
systemctl list-units --failed
列出全部正在運行,類型爲服務的單元
systemctl list-units --type=service
|
systemctl status
|
查看系統狀態
systemctl status
查看服務狀態
systemctl status ***.service
查看遠端主機的服務狀態
systemctl -H user@hostname status ***.service
|
|
unit 管理
|
啓動服務
sudo systemctl start ***.service
中止服務
sudo systemctl stop ***.service
重啓服務
sudo systemctl restart ***.service
殺死服務產生的全部子進程
sudo systemctl kill ***.service
從新加載服務配置文件
sudo systemctl reload ***.service
從新加載全部修改單元的配置文件
sudo systemctl daemon-reload
顯示 unit 的底層參數
sudo systemctl show ***.service
|
|
systemctl list-dependencies
|
列出服務的依賴關係
systemctl list-dependencies ***.service
列出服務的反向依賴關係
systemctl list-dependencies --reverse ***.service
查看 target 包含的 unit
systemctl list-dependencies ***.target
|
|
unit 配置文件
|
查看 unit 配置文件的內容
systemctl cat ***.service
查看全部配置文件
systemctl list-unit-files
查看指定類型的配置文件
systemctl list-unit-files --type=service
|
|
Target
|
查看系統的全部 target
systemctl list-unit-files --type=target
查看 target 包含的 unit
systemctl list-dependencies ***.target
查看啓動時的默認 target
systemctl get-default
|
|
日誌管理
|
journalctl
|
查看本次系統啓動的全部日誌
journalctl
查看指定 Unit 的日誌
journalctl -u ***.service
滾動顯示最新的日誌
journalctl -f
查看指定時間的日誌
journalctl --since "2020-05-06 01:00" --until "2020-05-06 03:00"
|
[root@lianhua ~]$ systemd-analyze critical-chain sshd.service The time after the unit is active or started is printed after the "@" character. The time the unit takes to start is printed after the "+" character. sshd.service +16ms └─cloud-init.service @6.503s +9.732s └─network.service @3.352s +3.121s └─network-pre.target @3.348s └─cloud-init-local.service @1.665s +1.682s └─dbus.socket @1.659s └─sysinit.target @1.628s └─systemd-update-utmp.service @1.614s +13ms └─auditd.service @1.424s +182ms └─systemd-tmpfiles-setup.service @1.394s +16ms └─rhel-import-state.service @1.341s +40ms └─local-fs.target @1.325s └─ephemeral.mount @747ms +577ms └─local-fs-pre.target @728ms └─lvm2-monitor.service @368ms +359ms └─lvm2-lvmetad.service @484ms └─lvm2-lvmetad.socket @329ms └─-.slice
[root@lianhua ~]$ systemctl status sshd.service ● sshd.service - OpenSSH server daemon Loaded: loaded (/usr/lib/systemd/system/sshd.service; enabled; vendor preset: enabled) Active: active (running) since Fri 2019-11-01 18:35:20 CST; 6 months 3 days ago Docs: man:sshd(8) man:sshd_config(5) Main PID: 8621 (sshd) Memory: 24.7M CGroup: /system.slice/sshd.service └─8621 /usr/sbin/sshd -D Nov 01 18:35:20 lianhua systemd[1]: Starting OpenSSH server daemon...
[root@lianhua ~]$ systemctl list-dependencies sshd.service sshd.service ● ├─sshd-keygen.service ● ├─system.slice ● └─basic.target ● ├─microcode.service ● ├─rhel-dmesg.service ● ├─selinux-policy-migrate-local-changes@targeted.service ...
[root@lianhua ~]$ systemctl list-dependencies --reverse sshd.service sshd.service ● ├─cloud-init.service ● └─multi-user.target ● └─graphical.target
[root@lianhua ~]$ systemctl cat sshd.service # /usr/lib/systemd/system/sshd.service [Unit] Description=OpenSSH server daemon Documentation=man:sshd(8) man:sshd_config(5) After=network.target sshd-keygen.service Wants=sshd-keygen.service [Service] Type=notify EnvironmentFile=/etc/sysconfig/sshd ExecStart=/usr/sbin/sshd -D $OPTIONS ExecReload=/bin/kill -HUP $MAINPID KillMode=process Restart=on-failure RestartSec=42s [Install] WantedBy=multi-user.target
[root@lianhua ~]$ systemctl list-unit-files UNIT FILE STATE tmp.mount disabled brandbot.path enabled auth-rpcgss-module.service static autofs.service disabled systemd-timedated.service masked ...
# autofs.service disabled [root@lianhua ~]# systemctl cat autofs.service # /usr/lib/systemd/system/autofs.service [Unit] ... [Service] ... [Install] WantedBy=multi-user.target [root@lianhua ~]# ll /etc/systemd/system/multi-user.target.wants/ | grep autofs.service [root@lianhua ~]# # brandbot.path enabled [root@lianhua ~]$ systemctl cat brandbot.path # /usr/lib/systemd/system/brandbot.path [Unit] ... [Path] ... [Install] WantedBy=multi-user.target [root@lianhua ~]$ ll /etc/systemd/system/multi-user.target.wants/ | grep brand lrwxrwxrwx. 1 root root 37 May 9 2018 brandbot.path -> /usr/lib/systemd/system/brandbot.path # systemd-timedated.service masked [root@lianhua ~]# ll /etc/systemd/system | grep systemd-timedated.service lrwxrwxrwx. 1 root root 9 Aug 12 2018 systemd-timedated.service -> /dev/null # auth-rpcgss-module.service static [root@lianhua ~]# systemctl cat auth-rpcgss-module.service [Unit] ... [Service] ...
[root@lianhua ~]# systemctl is-enabled autofs.service disabled [root@lianhua ~]# systemctl enable autofs.service Created symlink /etc/systemd/system/multi-user.target.wants/autofs.service → /usr/lib/systemd/system/autofs.service. [root@lianhua ~]# systemctl is-enabled autofs.service enabled
[root@lianhua ~]# systemctl status autofs.service ● autofs.service - Automounts filesystems on demand Loaded: loaded (/usr/lib/systemd/system/autofs.service; enabled; vendor preset: disabled) Active: inactive (dead)
/etc/systemd/system-preset/*.preset /run/systemd/system-preset/*.preset /usr/lib/systemd/system-preset/*.preset /etc/systemd/user-preset/*.preset /run/systemd/user-preset/*.preset /usr/lib/systemd/user-preset/*.preset
[root@lianhua ~]# ll /usr/lib/systemd/system-preset/ total 24 -rw-r--r--. 1 root root 264 Sep 25 2019 85-display-manager.preset -rw-r--r--. 1 root root 3982 Sep 25 2019 90-default.preset -rw-r--r--. 1 root root 951 Jun 22 2018 90-systemd.preset [root@lianhua ~]# cat /usr/lib/systemd/system-preset/90-systemd.preset enable remote-fs.target disable console-getty.service disable debug-shell.service
[root@lianhua process]$ systemctl status autofs.service ● autofs.service - Automounts filesystems on demand Loaded: loaded (/usr/lib/systemd/system/autofs.service; enabled; vendor preset: disabled) Active: active (running) since Mon 2019-08-05 17:42:46 CST; 9 months 0 days ago Process: 23921 ExecReload=/usr/bin/kill -HUP $MAINPID (code=exited, status=0/SUCCESS) [root@lianhua process]$ cat /usr/lib/systemd/system/autofs.service.d/app.conf [Service] User= User=app [root@lianhua process]$ systemctl daemon-reload [root@lianhua process]$ systemctl restart autofs.service [root@lianhua process]$ systemctl status autofs.service ● autofs.service - Automounts filesystems on demand Loaded: loaded (/usr/lib/systemd/system/autofs.service; enabled; vendor preset: disabled) Drop-In: /usr/lib/systemd/system/autofs.service.d └─app.conf Active: active (running) since Mon 2019-08-05 17:42:46 CST; 9 months 0 days ago
[root@lianhua ~]# systemctl cat cloud-config.target [Unit] Description=Cloud-config availability Wants=cloud-init-local.service cloud-init.service After=cloud-init-local.service cloud-init.service [root@lianhua ~]# systemctl status cloud-config.target ● cloud-config.target - Cloud-config availability Loaded: loaded (/usr/lib/systemd/system/cloud-config.target; static; vendor preset: disabled) Active: active since Fri 2020-03-13 09:18:36 UTC; 1 months 22 days ago
[root@lianhua ~]# systemctl status systemd-ask-password-wall.path ● systemd-ask-password-wall.path - Forward Password Requests to Wall Directory Watch Loaded: loaded (/usr/lib/systemd/system/systemd-ask-password-wall.path; static; vendor preset: disabled) Active: active (waiting) since Fri 2020-03-13 09:17:52 UTC; 1 months 22 days ago Docs: man:systemd-ask-password-console.service(8) [root@lianhua ~]# systemctl cat systemd-ask-password-wall.path [Unit] Description=Forward Password Requests to Wall Directory Watch ... [Path] DirectoryNotEmpty=/run/systemd/ask-password MakeDirectory=yes [root@lianhua ~]# systemctl status systemd-ask-password-wall ● systemd-ask-password-wall.service - Forward Password Requests to Wall Loaded: loaded (/usr/lib/systemd/system/systemd-ask-password-wall.service; static; vendor preset: disabled) Active: inactive (dead) Docs: man:systemd-ask-password-console.service(8)
[root@lianhua process]$ systemctl status build.mount ● build.mount - /build Loaded: loaded (/etc/fstab; bad; vendor preset: disabled) Active: active (mounted) since Mon 2019-08-05 17:42:44 CST; 9 months 0 days ago Where: /build What: lianhua.net:/vol/test/build/build Docs: man:fstab(5) man:systemd-fstab-generator(8) Memory: 0B Aug 05 17:42:44 lianhua systemd[1]: Mounting /build... Aug 05 17:42:44 lianhua systemd[1]: Mounted /build. [root@lianhua process]$ systemctl cat build.mount [Unit] SourcePath=/etc/fstab Documentation=man:fstab(5) man:systemd-fstab-generator(8) Before=remote-fs.target [Mount] What=lianhua.net:/vol/test/build/build Where=/build Type=nfs Options=soft,intr,retry=1,rw,rsize=32768,wsize=32768 [root@lianhua process]$ df -hT | grep /build lianhua.net:/vol/test/build/build nfs 21T 17T 4.3T 80% /build