Files
ykxmz/_build/check_ingress.sh
T
xmz7891 f4a146056f 修开机慢 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 ✓
2026-10-07 10:27:07 +08:00

61 lines
2.7 KiB
Bash

#!/bin/bash
# 502/530 但隧道连着 —— 查回源配置(这是我唯一还没验证过的一环)
set -u
BASE=http://127.0.0.1:8080
echo "════════ 1. 隧道 ingress 配置全文 ════════"
cat /root/.cloudflared/config.yml 2>/dev/null | sed 's/^/ /'
echo
echo "════════ 2. relay 到底监听哪个地址 ════════"
ss -lntp 2>/dev/null | grep 8080 | sed 's/^/ /'
echo " ---"
printf " 127.0.0.1:8080 -> HTTP %s\n" "$(curl -s -o /dev/null -w '%{http_code}' --max-time 5 http://127.0.0.1:8080/v1/health)"
printf " localhost:8080 -> HTTP %s\n" "$(curl -s -o /dev/null -w '%{http_code}' --max-time 5 http://localhost:8080/v1/health)"
printf " 192.168.10.105:8080 -> HTTP %s\n" "$(curl -s -o /dev/null -w '%{http_code}' --max-time 5 http://192.168.10.105:8080/v1/health)"
echo
echo "════════ 3. cloudflared 能看到 relay 吗(同一台机器)════════"
echo " cloudflared 进程:"
pgrep -af 'cloudflared tunnel' | head -2 | sed 's/^/ /'
echo
echo "════════ 4. 隧道 metrics 全量 ════════"
curl -s --max-time 5 http://127.0.0.1:20241/metrics 2>/dev/null \
| grep -E '^cloudflared_tunnel' | sed 's/^/ /'
echo
echo "════════ 5. 最近的注册/掉线(看 4 条是不是刚连上的)════════"
tail -300 /root/lanremote-relay/tunnel.log 2>/dev/null \
| grep -E 'Registered|Lost|Retrying|i/o timeout|error' \
| tail -20 | sed 's/^/ /'
echo
echo "════════ 6. 公网连打 15 次(看是持续挂还是间歇)════════"
ok=0
for i in $(seq 1 15); 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/15"
echo
echo "════════ 7. 每次请求是不是落到不同机房 ════════"
for i in 1 2 3 4 5 6; do
ray=$(curl -sI --max-time 12 -H 'User-Agent: LanRemote/1.4.0' \
https://relay.xxmxxs.top/v1/health 2>/dev/null \
| grep -i '^cf-ray' | tr -d '\r' | awk '{print $2}')
code=$(curl -s -o /dev/null -w '%{http_code}' --max-time 12 \
-H 'User-Agent: LanRemote/1.4.0' https://relay.xxmxxs.top/v1/health)
printf " HTTP %s cf-ray %s\n" "$code" "$ray"
done
echo
echo "════════ 8. DNS 解析到哪 ════════"
getent ahostsv4 relay.xxmxxs.top 2>/dev/null | awk '{print $1}' | sort -u | sed 's/^/ v4: /'
getent ahostsv6 relay.xxmxxs.top 2>/dev/null | awk '{print $1}' | sort -u | head -3 | sed 's/^/ v6: /'