#!/bin/bash # 发一个公网请求,紧跟着看隧道日志处理了什么 —— 定位 502 到底出在哪一段 set -u RELAY_DIR=/root/lanremote-relay echo "════════ 1. 打标记,好区分新旧日志 ════════" echo "---- PROBE $(date -u +%H:%M:%S) ----" >> "$RELAY_DIR/tunnel.log" before=$(wc -l < "$RELAY_DIR/tunnel.log") echo " 日志当前 $before 行" echo echo "════════ 2. 从设备自己请求公网(发夹回路,但能看出链路上通不通)════════" curl -s -o /tmp/pub.out -w ' HTTP %{http_code} 用时 %{time_total}s 大小 %{size_download}\n' \ --max-time 30 -H 'User-Agent: LanRemote/1.4.0' https://relay.xxmxxs.top/v1/health echo " 响应头 5 行:" head -5 /tmp/pub.out | sed 's/^/ /' echo echo "════════ 3. 请求短路径(首页,只有 15KB)════════" curl -s -o /tmp/pub2.out -w ' HTTP %{http_code} 用时 %{time_total}s 大小 %{size_download}\n' \ --max-time 30 -H 'User-Agent: LanRemote/1.4.0' https://relay.xxmxxs.top/ head -3 /tmp/pub2.out | sed 's/^/ /' echo echo "════════ 4. 请求一个极小的路径 ════════" curl -s -o /dev/null -w ' /favicon.ico HTTP %{http_code} 用时 %{time_total}s 大小 %{size_download}\n' \ --max-time 30 -H 'User-Agent: LanRemote/1.4.0' https://relay.xxmxxs.top/favicon.ico echo echo "════════ 5. 这几条请求之后,隧道日志新增了什么 ════════" after=$(wc -l < "$RELAY_DIR/tunnel.log") echo " 新增 $((after - before)) 行:" tail -n +$((before + 1)) "$RELAY_DIR/tunnel.log" | tail -30 | sed 's/^/ /' echo echo "════════ 6. 隧道 metrics 变化 ════════" curl -s --max-time 5 http://127.0.0.1:20241/metrics 2>/dev/null \ | grep -E '^cloudflared_tunnel_(total_requests|request_errors|response_by_code)' | sed 's/^/ /' echo echo "════════ 7. relay 自己的日志(不是 journal,是它可能写的文件)════════" ls -la "$RELAY_DIR"/*.log 2>/dev/null | sed 's/^/ /' echo " relay 最近通过隧道服务的请求(如果有访问日志):" journalctl -u lanremote-relay --since '2 minutes ago' --no-pager 2>/dev/null | tail -10 | sed 's/^/ /'