修开机慢 2 分钟:掉电重启后要 2 分 10 秒才能恢复

用户早上撞上 Cloudflare Error 1033。查出来是设备**掉电重启**:
上次开机到重启之间没有任何日志落盘(直接断电的特征),
dmesg 里还有 "l13: voltage operation not allowed"。

重启本身不是软件问题,但**恢复太慢**:
    Startup finished in 3.846s (kernel) + 2min 6.358s (userspace) = 2分10秒
那 2 分钟里浏览器看到的就是 1033。

根因:
    这台机器 NetworkManager 和 systemd-networkd 同时在跑,
    但 wlan0 归 NetworkManager 管。
      NetworkManager-wait-online   -> 开机 9 秒成功
      systemd-networkd-wait-online -> 等一个不归它管的网络,
                                      干等 2 分钟超时,然后 failed
    network-online.target 要等**两个都完成**,
    被那个失败的拖了整整 2 分钟,
    relay / tunnel / net-tune 全跟着等。

修法:
  1. mask 掉 systemd-networkd-wait-online(网络不归它管,只会拖后腿)
  2. watchdog 首次检查从"开机后 2 分钟"提前到 45 秒

实测(重启验证过):
    修之前  Startup finished in 3.846s + 2min 6.358s = 2分10秒
    修之后  Startup finished in 3.218s +   14.060s =   17.3秒
    掉电重启后公网恢复时间:**24 秒**(快了 5 倍多)

配套加了 scripts/speed-up-boot.sh,换设备时直接跑一遍。

顺带确认重启后一切自动恢复:
    三个服务 active + enabled ✓
    keepalive 30/10/3、MTU 探测、MSS 钳制、slow_start=0 全部持久化 ✓
    隧道 4 条连接 http2 ✓
    官网 / 管理页 / 截图全部 200 ✓
This commit is contained in:
xmz7891
2026-10-07 10:27:07 +08:00
parent bcb089eded
commit f4a146056f
12 changed files with 636 additions and 25 deletions
+57
View File
@@ -0,0 +1,57 @@
#!/bin/bash
# 重启后全面体检
set -u
echo "════════ 开机信息 ════════"
uptime -p | sed 's/^/ /'
systemd-analyze 2>/dev/null | sed 's/^/ /'
echo
echo "════════ 服务 ════════"
for s in lanremote-relay lanremote-tunnel lanremote-nettune lanremote-watchdog.timer NetworkManager-wait-online; do
printf " %-30s %-10s %s\n" "$s" "$(systemctl is-active $s 2>&1)" "$(systemctl is-enabled $s 2>&1)"
done
echo " ---"
echo " systemd-networkd-wait-online: $(systemctl is-enabled systemd-networkd-wait-online 2>&1) (应该是 masked)"
echo
echo "════════ 网络调优是否持久化 ════════"
for k in tcp_keepalive_time tcp_keepalive_intvl tcp_keepalive_probes tcp_mtu_probing tcp_slow_start_after_idle tcp_congestion_control; do
printf " %-32s = %s\n" "$k" "$(sysctl -n net.ipv4.$k 2>/dev/null || echo '?')"
done
echo " MSS 钳制: $(iptables -t mangle -S 2>/dev/null | grep -c TCPMSS) 条"
echo
echo "════════ 隧道 ════════"
echo " 连接数: $(curl -s --max-time 5 http://127.0.0.1:20241/metrics 2>/dev/null | grep '^cloudflared_tunnel_ha_connections' | awk '{print $2}')"
echo " 落点:"
grep -E 'Registered tunnel connection' /root/lanremote-relay/tunnel.log 2>/dev/null | tail -4 \
| grep -oE 'location=[a-z0-9]+ protocol=[a-z0-9]+' | sed 's/^/ /'
echo " 参数:"
grep -oE '\-\-protocol [a-z0-9]+|--ha-connections [0-9]+' /etc/systemd/system/lanremote-tunnel.service | sed 's/^/ /'
echo
echo "════════ 本机中转 ════════"
echo " HTTP $(curl -s -o /dev/null -w '%{http_code}' --max-time 8 http://127.0.0.1:8080/v1/health)"
echo
echo "════════ 公网 12 次 ════════"
ok=0
for i in $(seq 1 12); do
c=$(curl -s -o /dev/null -w '%{http_code}' --max-time 15 \
-H 'User-Agent: LanRemote/1.4.0' https://relay.xxmxxs.top/v1/health)
[ "$c" = "200" ] && ok=$((ok+1))
printf " %2d: %s\n" "$i" "$c"
sleep 1
done
echo " 可用 $ok/12"
echo
echo "════════ 官网 + 管理页 ════════"
echo " 官网 HTTP $(curl -s -o /dev/null -w '%{http_code}' --max-time 15 https://relay.xxmxxs.top/)"
echo " 管理页 HTTP $(curl -s -o /dev/null -w '%{http_code}' --max-time 15 https://relay.xxmxxs.top/zhongzhuanzhan)"
echo " 截图 HTTP $(curl -s -o /dev/null -w '%{http_code}' --max-time 15 https://relay.xxmxxs.top/shot/pc-main.png)"
echo
echo "════════ watchdog 日志 ════════"
tail -6 /root/lanremote-relay/watchdog.log 2>/dev/null | sed 's/^/ /'