systemd-analyze 命令详解

| 选择喜欢的代码风格  

A B C D E F G H I J K L M N O P Q R S T U V W X Y Z

systemd-analyze 命令安装:


-bash/zsh: systemd-analyze command not found

# Windows (WSL2)
sudo apt-get update sudo apt-get install systemd

# Debian
apt-get install systemd

# Ubuntu
apt-get install systemd

# Arch Linux
pacman -S systemd

# Kali Linux
apt-get install systemd

# CentOS
yum install systemd

# Fedora
dnf install systemd

# Raspbian
apt-get install systemd

# Dockerfile
dockerfile.run/systemd-analyze

systemd-analyze 命令补充说明:


systemd-analyze 是一个分析启动性能的工具,用于分析启动时服务时间消耗。默认显示启动是内核和用户空间的消耗时间:使用 systemd-analyze plot > boot.svg 生成一张启动详细信息矢量图,然后用图像浏览器或者网页浏览器打开查看 。

systemd-analyze 命令语法:


systemd-analyze [OPTIONS...] [time]

systemd-analyze [OPTIONS...] blame

systemd-analyze [OPTIONS...] critical-chain [UNIT...]

systemd-analyze [OPTIONS...] dump [PATTERN...]

systemd-analyze [OPTIONS...] plot [>file.svg]

systemd-analyze [OPTIONS...] dot [PATTERN...] [>file.dot]

systemd-analyze [OPTIONS...] unit-files

systemd-analyze [OPTIONS...] unit-paths

systemd-analyze [OPTIONS...] exit-status [STATUS...]

systemd-analyze [OPTIONS...] capability [CAPABILITY... | {-m | --mask} MASK]

systemd-analyze [OPTIONS...] condition CONDITION...

systemd-analyze [OPTIONS...] syscall-filter [SET...]

systemd-analyze [OPTIONS...] filesystems [SET...]

systemd-analyze [OPTIONS...] calendar SPEC...

systemd-analyze [OPTIONS...] timestamp TIMESTAMP...

systemd-analyze [OPTIONS...] timespan SPAN...

systemd-analyze [OPTIONS...] cat-config NAME|PATH...

systemd-analyze [OPTIONS...] compare-versions VERSION1 [OP] VERSION2

systemd-analyze [OPTIONS...] verify FILE...

systemd-analyze [OPTIONS...] security [UNIT...]

systemd-analyze [OPTIONS...] inspect-elf FILE...

systemd-analyze [OPTIONS...] malloc [D-BUS SERVICE...]

systemd-analyze [OPTIONS...] fdstore UNIT...

systemd-analyze [OPTIONS...] image-policy POLICY...

systemd-analyze [OPTIONS...] has-tpm2

systemd-analyze [OPTIONS...] pcrs [PCR...]

systemd-analyze [OPTIONS...] srk [>FILE]

systemd-analyze [OPTIONS...] architectures [NAME...]

systemd-analyze [OPTIONS...] smbios11

systemd-analyze 命令选项:


--user
   Operates on the user systemd instance.

--system
   Operates on the system systemd instance. This is the implied default.

--order, --require
   When used in conjunction with the dot command (see above), selects which dependencies
   are shown in the dependency graph. If --order is passed, only dependencies of type
   After= or Before= are shown. If --require is passed, only dependencies of type
   Requires=, Requisite=, Wants= and Conflicts= are shown. If neither is passed, this
   shows dependencies of all these types.

--from-pattern=, --to-pattern=
   When used in conjunction with the dot command (see above), this selects which
   relationships are shown in the dependency graph. Both options require a glob(7)
   pattern as an argument, which will be matched against the left-hand and the
   right-hand, respectively, nodes of a relationship.

   Each of these can be used more than once, in which case the unit name must match one
   of the values. When tests for both sides of the relation are present, a relation must
   pass both tests to be shown. When patterns are also specified as positional arguments,
   they must match at least one side of the relation. In other words, patterns specified
   with those two options will trim the list of edges matched by the positional
   arguments, if any are given, and fully determine the list of edges shown otherwise.

--fuzz=timespan
   When used in conjunction with the critical-chain command (see above), also show units,
   which finished timespan earlier, than the latest unit in the same level. The unit of
   timespan is seconds unless specified with a different unit, e.g. "50ms".

--man=no
   Do not invoke man to verify the existence of man pages listed in Documentation=.

--generators
   Invoke unit generators, see systemd.generator(7). Some generators require root
   privileges. When run under a normal users, enabling generators will generally result
   in some warnings.

-H, --host=
   Execute the operation remotely. Specify a hostname, or a username and hostname
   separated by "@", to connect to. The hostname may optionally be suffixed by a
   container name, separated by ":", which connects directly to a specific container on
   the specified host. This will use SSH to talk to the remote machine manager instance.
   Container names may be enumerated with machinectl -H HOST.

-M, --machine=
   Execute operation on a local container. Specify a container name to connect to.

-h, --help
   Print a short help text and exit.

--version
   Print a short version string and exit.

--no-pager
   Do not pipe output into a pager.

systemd-analyze 命令实例:


systemd-analyze 列出所有正在运行的单元,按初始化时间排序:

systemd-analyze blame

# 输入如下示例
25.634s kdump.service
21.346s sendmail.service
7.898s network.service
5.775s NetworkManager-wait-online.service
3.389s mariadb.service
1.605s named.service
1.357s dev-mapper-centos\x2droot.device
1.130s snmpd.service
1.064s tuned.service
676ms httpd.service
674ms lvm2-monitor.service
563ms systemd-tmpfiles-setup-dev.service
518ms NetworkManager.service
492ms lvm2-pvscan@8:2.service
334ms rhel-readonly.service
330ms home.mount
305ms var.mount
300ms fail2ban.service
257ms sshd.service
206ms systemd-sysctl.service
188ms tmp.mount
186ms systemd-logind.service
184ms named-setup-rndc.service
181ms sm-client.service
171ms backup.mount
170ms rsyslog.service
157ms systemd-tmpfiles-clean.service
147ms systemd-udevd.service
133ms boot.mount
129ms systemd-journald.service
125ms polkit.service
...

systemd-analyze 打印时间关键单元链的树:

systemd-analyze critical-chain

# 类似如下输出:
multi-user.target @39.664s
└─sm-client.service @39.290s +181ms
└─sendmail.service @17.943s +21.346s
└─network.target @17.922s
└─network.service @10.023s +7.898s
└─NetworkManager-wait-online.service @4.246s +5.775s
└─NetworkManager.service @3.727s +518ms
└─dbus.service @3.549s
└─basic.target @3.544s
└─paths.target @3.544s
└─brandbot.path @3.544s
└─sysinit.target @3.543s
└─systemd-update-utmp.service @3.516s +26ms
└─auditd.service @3.423s +91ms
└─systemd-tmpfiles-setup.service @3.331s +90ms
└─rhel-import-state.service @3.284s +45ms
└─local-fs.target @3.242s
└─home.mount @2.911s +330ms
└─dev-mapper-centos\x2dhome.device @2.909s

systemd-analyze 创建一个 SVG 文件,显示每个系统服务的启动时间,并突出显示它们初始化所花费的时间:

systemd-analyze plot > path/to/file.svg

systemd-analyze 绘制依赖关系图并将其转换为 SVG 文件:

systemd-analyze dot | dot -Tsvg > path/to/file.svg

systemd-analyze 显示正在运行的单元的安全分数:

systemd-analyze security

systemd-analyze 命令扩展阅读:




systemd-analyze 命令评论

共收录到 512Linux 命令