解决阿里云 Debian VPS 启动慢的问题

Oct 13, 2024 • 预计阅读时间 1 分钟

阿里云的轻量服务器提供的 Debian 镜像是 11 版本的,自己升级到 12 以后,发现从系统启动到网络可用期间,需要花很长时间。

提供命令分析启动的时候各个服务花了多少时间:

$ systemd-analyze blame

原来是卡在了 systemd-networkd-wait-online.service 这个服务上,一直等待这个服务直到超时为止,难怪启动时间那么久。

简单解决方法是给这个服务设置一个超时时间,等待 5 秒:

编辑文件:/etc/systemd/system/network-online.target.wants/systemd-networkd-wait-online.service

添加一行:TimeoutStartSec=5sec

#  SPDX-License-Identifier: LGPL-2.1-or-later
#
#  This file is part of systemd.
#
#  systemd is free software; you can redistribute it and/or modify it
#  under the terms of the GNU Lesser General Public License as published by
#  the Free Software Foundation; either version 2.1 of the License, or
#  (at your option) any later version.

[Unit]
Description=Wait for Network to be Configured
Documentation=man:systemd-networkd-wait-online.service(8)
DefaultDependencies=no
Conflicts=shutdown.target
BindsTo=systemd-networkd.service
After=systemd-networkd.service
Before=network-online.target shutdown.target

[Service]
Type=oneshot
ExecStart=/lib/systemd/systemd-networkd-wait-online
RemainAfterExit=yes
TimeoutStartSec=5sec

[Install]
WantedBy=network-online.target
Debian
版权声明:如果转发请带上本文链接和注明来源。

lvv.me

iOS/macOS Developer

使用 xcodebuild 下载 SDK