#!/bin/bash # 15 分钟长测:确认 MTU 修复后 90%+ 能稳住。 set -u RELAY_DIR=/root/lanremote-relay URL=https://relay.xxmxxs.top 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 " tcp_mtu_probing=$(cat /proc/sys/net/ipv4/tcp_mtu_probing)" echo " MSS 规则=$(iptables -t mangle -L -n 2>/dev/null | grep -ci mss) 条" : > "$RELAY_DIR/tunnel.log" echo " 连续探 15 分钟(每 5 秒一次,共 180 次)…" ok=0; bad=0; consec=0; maxconsec=0 for i in $(seq 1 180); do c=$(timeout 12 curl -4 -s -o /dev/null -w '%{http_code}' \ -H 'User-Agent: LanRemote/1.4.0' "$URL/v1/health" 2>/dev/null) c=${c:-000} if [ "$c" = "200" ]; then ok=$((ok+1)); consec=0 else bad=$((bad+1)); consec=$((consec+1)) [ "$consec" -gt "$maxconsec" ] && maxconsec=$consec fi sleep 5 done pct=$((ok * 100 / 180)) echo echo "===== 结果 =====" echo " 可用 $ok/180 = ${pct}%" echo " 最长连续失败 ${maxconsec} 次(约 $((maxconsec * 5)) 秒)" echo echo " 隧道:注册 $(grep -c 'Registered tunnel connection' "$RELAY_DIR/tunnel.log" 2>/dev/null || echo 0) 次 ·" \ "断开 $(grep -c 'Connection terminated' "$RELAY_DIR/tunnel.log" 2>/dev/null || echo 0) 次 ·" \ "Bad request $(grep -c 'Bad request syntax' "$RELAY_DIR/tunnel.log" 2>/dev/null || echo 0) 次" echo echo " 看门狗动作:" tail -4 "$RELAY_DIR/watchdog.log" 2>/dev/null | sed 's/^/ /' echo echo "===== 对比 =====" echo " 修之前 48% ~ 75%" echo " MTU 修复后 ${pct}%" if [ "$pct" -ge 90 ]; then echo " ✓ 达标" else echo " ~ 未达 90%" fi