#!/bin/bash # 为什么只建了 1 条隧道连接?(配置是 ha-connections 2) # # 观察: # 100% 那次:连接数 2 # 85% 那次:连接数 1 # -> 连接数直接决定可用率!缺一条就少一份冗余。 set -u RELAY_DIR=/root/lanremote-relay echo "===== 1. 现在的连接数 =====" echo " 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 echo "===== 2. 等 90 秒,看第二条会不会自己补上 =====" for i in 1 2 3 4 5 6; do sleep 15 n=$(curl -s --max-time 5 http://127.0.0.1:20241/metrics 2>/dev/null | grep '^cloudflared_tunnel_ha_connections' | awk '{print $2}') echo " ${i}5s: 连接数 = ${n:-?}" done echo echo "===== 3. 隧道日志里的注册/断开 =====" grep -E 'Registered tunnel connection|Connection terminated|Failed to dial|Lost connection' \ "$RELAY_DIR/tunnel.log" 2>/dev/null | tail -12 | sed 's/^/ /' echo echo "===== 4. 配置文件里的 ha-connections =====" grep -n 'ha-connections' /etc/systemd/system/lanremote-tunnel.service \ | sed 's/^/ /' echo echo "===== 5. 用 4 条连接试试(MSS 修好之后 TCP 多连接应该更从容)=====" cat > /etc/systemd/system/lanremote-tunnel.service <<'EOF' [Unit] Description=LanRemote Cloudflare 具名隧道 After=network-online.target lanremote-relay.service lanremote-nettune.service Wants=network-online.target lanremote-relay.service [Service] Type=simple # 协议 HTTP/2:这条线路丢 UDP 包,QUIC 撑不住(实测 48% vs 80%) # 连接数 4:MSS 夹好之后 TCP 多连接不再互相挤, # 缺一条还有三条顶着(实测连接数 1 时掉到 85%) ExecStart=/usr/local/bin/cloudflared tunnel --no-autoupdate --protocol http2 --edge-ip-version 4 --ha-connections 4 --retries 5 --config /root/.cloudflared/config.yml run lanremote Restart=always RestartSec=5 MemoryMax=200M StandardOutput=append:/root/lanremote-relay/tunnel.log StandardError=append:/root/lanremote-relay/tunnel.log [Install] WantedBy=multi-user.target EOF systemctl daemon-reload systemctl restart lanremote-tunnel echo " 已切到 4 条,等 60 秒…" sleep 60 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 " 注册 $(grep -c 'Registered tunnel connection' "$RELAY_DIR/tunnel.log" 2>/dev/null || echo 0) 次" echo echo "===== 6. 30 次可用率 =====" ok=0 for i in $(seq 1 30); do c=$(timeout 12 curl -4 -s -o /dev/null -w '%{http_code}' \ -H 'User-Agent: LanRemote/1.4.0' https://relay.xxmxxs.top/v1/health 2>/dev/null) [ "$c" = "200" ] && ok=$((ok+1)) sleep 1 done echo " $ok/30 = $((ok * 100 / 30))%"