Systemd starts the performance optimization tool systemd-analyze
-
- Introduction to systemd-analyze
-
- List all directories related to the unit
- Check the total time taken to start systemd
- View systemd startup time-consuming details
- Display dependencies and time information between key systemd units during system startup
- Check which services started at startup can be optimized
- Export to SVG analysis chart
- Check whether the service unit (units) file syntax is correct
- Analyze the security and sandbox settings of a specified service unit
- Check the log level set by systemd
- Temporarily set systemd log level
- Permanently modify systemd log level
- Print the current log level of the systemd daemon
- View the current log target of the systemd daemon
- Temporarily modify the systemd log target
- Show details of all system call collections
Introduction to systemd-analyze
systemd-analyze
It is a command line tool used to analyze and diagnose Systemd startup performance. It is mainly used to analyze and optimize systemd system startup speed.
https://opensource.com/article/20/9/systemd-startup-configuration
https://blog.csdn.net/easylife206/article/details/103790052
https://www.redhat.com/sysadmin/mastering-systemd
https://www.jinbuguo.com/systemd/systemd-analyze.html
List all directories related to the unit
Including:
unit file directory, configuration fragment directory (.d), dependency directory (.wants and .requires).
When used with --user, it targets the systemd user instance.
When used with --global, indicates global configuration for systemd user instances.
# 列出与单元相关的全部目录
systemd-analyze unit-paths
Check the total time taken to start systemd
# 查看systemd启动总耗时
systemd-analyze
View systemd startup time-consuming details
# 查看systemd启动耗时明细
systemd-analyze blame
Display dependencies and time information between key systemd units during system startup
# 显示系统启动过程中关键的systemd单元(units)之间的依赖关系和时间信息
systemd-analyze critical-chain
View specified service startup dependencies and time information
You can see network.service
that it took the longest, 17.201
seconds.
The timing here may be waiting for other servers to start. Let’s take a look at the startup time of its associated services:
# 查看指定服务启动依赖关系和时间信息
systemd-analyze critical-chain network.service
Check which services started at startup can be optimized
# 查看有哪些开机启动的服务可被优化
systemctl list-unit-files --type=service | grep enabled
Export to SVG analysis chart
# 导出到SVG分析图
systemd-analyze plot > /tmp/bootup.svg
# 生成描述单元间依赖关系的 SVG 图
systemd-analyze dot | dot -Tsvg > systemd.svg
Check whether the service unit (units) file syntax is correct
After creating the new unit file, verify that its syntax is correct and, if configured 正确
, 不会有输出
.
# 服务单元(units)文件验证
systemd-analyze verify 服务单元路径
Analyze the security and sandbox settings of a specified service unit
# 分析指定服务单元的安全性和沙箱设置
systemd-analyze security 服务单元
Check the log level set by systemd
# 查看systemd当前设置的日志级别
systemctl -pLogLevel show
Temporarily set systemd log level
# 临时修改systemd的日志级别为notice
systemd-analyze set-log-level notice
# 查看systemd当前设置的日志级别
systemctl -pLogLevel show
Permanently modify systemd log level
# 修改systemd配置文件
vim /etc/systemd/system.conf
# 修改完配置后重启systemd守护进程
systemctl daemon-reload
Print the current log level of the systemd daemon
# 打印systemd守护进程当前的日志等级
systemd-analyze get-log-level
View the current log target of the systemd daemon
# 打印systemd 守护进程当前的日志目标
systemd-analyze get-log-target
Temporarily modify the systemd log target
# 将systemd守护进程的日志目标更改为 TARGET
systemd-analyze set-log-target TARGET
Show details of all system call collections
# 查看所有过滤器
systemd-analyze syscall-filter
systemd-analyze syscall-filter [SET…] If at least one SET parameter is specified, only the system call list contained in the specified set will be displayed; otherwise, the details of all system call sets will be displayed. Note that the "@" prefix must be included in the SET parameters.
# 查看指定过滤器
systemd-analyze syscall-filter @ipc