#!/bin/bash # 立刻恢复隧道 + 确认问题。 # # 现象:cloudflared 进程活着、指标说 ha_connections=1, # 但日志 8 小时没动静、公网 1033。 # -> 那是条"僵死连接":计数还在,实际早断了。 set -u RELAY_DIR=/root/lanremote-relay URL=https://relay.xxmxxs.top echo "===== 1. 重启之前 =====" echo -n " ha_connections = " curl -s --max-time 5 http://127.0.0.1:20241/metrics 2>/dev/null \ | grep '^cloudflared_tunnel_ha_connections' | awk '{print $2}' echo " 日志最后一条: $(tail -1 $RELAY_DIR/tunnel.log 2>/dev/null | cut -c1-30)" echo " 现在时间: $(date -u '+%Y-%m-%dT%H:%M:%SZ')" echo " 公网: HTTP $(timeout 15 curl -4 -s -o /dev/null -w '%{http_code}' -H 'User-Agent: LanRemote/1.4.0' $URL/v1/health 2>/dev/null)" echo echo "===== 2. 重启隧道 =====" systemctl restart lanremote-tunnel sleep 40 echo " 服务: $(systemctl is-active lanremote-tunnel)" echo -n " ha_connections = " 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 -c 'Registered tunnel connection' $RELAY_DIR/tunnel.log 2>/dev/null || echo 0)" echo echo "===== 3. 验证公网 =====" OK=0 for i in $(seq 1 10); do C=$(timeout 15 curl -4 -s -o /dev/null -w '%{http_code}' \ -H 'User-Agent: LanRemote/1.4.0' "$URL/v1/health" 2>/dev/null) [ "$C" = "200" ] && { OK=$((OK+1)); M="✓"; } || M="✗" printf " %2d: %s %s\n" "$i" "$M" "${C:-超时}" sleep 2 done echo " 公网 $OK / 10" echo echo "===== 4. 本地源站(对照)=====" echo " HTTP $(timeout 8 curl -s -o /dev/null -w '%{http_code}' http://127.0.0.1:8080/v1/health)" echo echo "===== 5. 结论 =====" if [ "$OK" -ge 8 ]; then echo " ✓ 重启后恢复了" echo " 问题定性:cloudflared 的连接僵死了,但指标还报 1 ——" echo " 看门狗只看指标,所以 8 小时没动作。" else echo " ✗ 重启也没恢复,链路本身可能不行" fi