使用 systemd-analyze 分析 Linux 系统启动慢的原因

使用 systemd-analyze 命令可以查看 Linux 系统在启动过程中每个服务的耗时情况, 方便我们排查是哪个环节导致系统启动缓慢, 以下是整理的常用命令参数和效果. 例子中一下子就可以定位到是 gssproxy.service 服务启动耗时过长.

systemd-analyze blame Print list of running units ordered by time to init
$ systemd-analyze blame

         29.912s gssproxy.service
         11.280s update-motd.service
          4.250s network.service
           426ms cloud-init-local.service
           302ms cloud-init.service
           276ms dracut-initqueue.service
           247ms cloud-config.service
           206ms cloud-final.service
           201ms systemd-udev-settle.service
           183ms initrd-switch-root.service
           175ms postfix.service
           158ms lvm2-monitor.service
systemd-analyze critical-chain Print a tree of the time critical chain of units
$ systemd-analyze critical-chain

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.

graphical.target @30.350s
└─multi-user.target @30.350s
  └─getty.target @30.350s
    └─getty@tty1.service @30.350s
      └─systemd-user-sessions.service @30.322s +2ms
        └─remote-fs.target @30.322s
          └─remote-fs-pre.target @30.322s
            └─nfs-client.target @30.322s
              └─gssproxy.service @409ms +29.912s
                └─basic.target @409ms
                  └─sockets.target @409ms
                    └─dbus.socket @409ms
                      └─sysinit.target @408ms
                        └─systemd-update-utmp.service @405ms +2ms
                          └─auditd.service @381ms +24ms
                            └─systemd-tmpfiles-setup.service @376ms +4ms
                              └─local-fs.target @375ms
                                └─local-fs-pre.target @299ms
                                  └─lvm2-monitor.service @140ms +158ms
                                    └─lvm2-lvmetad.service @162ms
                                      └─lvm2-lvmetad.socket @138ms
                                        └─-.slice
systemd-analyze plot Output SVG graphic showing service initialization
systemd-analyze plot > ~/plot.svg

导出的 svg 文件复制到本地电脑上就可以直接用浏览器打开看了

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

DexterLien

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值