#!/bin/bash # 502 诊断 v2 set -u echo " ══ 1. 三个服务 ══" for s in lanremote-relay lanremote-tunnel lanremote-tunnel-h2; do printf " %-24s %s\n" "$s" "$(systemctl is-active $s 2>/dev/null)" done echo echo " ══ 2. 所有 cloudflared 进程(看 protocol / metrics 端口)══" ps -eo pid,args 2>/dev/null | grep '[c]loudflared tunnel' | while read -r line; do echo " $line" | cut -c1-160 done echo echo " ══ 3. 两个 metrics 端口分别报几条连接 ══" for p in 20241 20242; do n=$(curl -s --max-time 4 "http://127.0.0.1:$p/metrics" 2>/dev/null \ | grep '^cloudflared_tunnel_ha_connections' | awk '{print $2}') printf " %s -> %s 条\n" "$p" "${n:-读不到}" done echo echo " ══ 4. 隧道 config.yml 的回源配置(关键:指向哪个端口)══" cat /root/.cloudflared/config.yml 2>/dev/null | sed 's/^/ /' echo echo " ══ 5. relay 实际监听端口 ══" ss -lntp 2>/dev/null | grep -E 'python|8080|8880' | sed 's/^/ /' || echo " (没看到)" echo echo " ══ 6. 本机 8080 ══" curl -s --max-time 8 -o /dev/null -w ' HTTP %{http_code} %{time_total}s\n' \ -H 'User-Agent: LanRemote/1.8.2' http://127.0.0.1:8080/v1/health echo echo " ══ 7. 公网(关键)══" curl -s --max-time 25 -o /dev/null -w ' HTTP %{http_code} %{time_total}s\n' \ -H 'User-Agent: LanRemote/1.8.2' https://relay.xxmxxs.top/v1/health echo echo " ══ 8. cloudflared 日志最近 25 行 ══" journalctl -u lanremote-tunnel -n 25 --no-pager 2>/dev/null | tail -25 | sed 's/^/ /'