#!/bin/bash # 回退到 QUIC,并做抗抖动调优。 # # 实测结论(很明确): # HTTP/2 走 TCP 7844 -> "TLS handshake with edge ... i/o timeout" # 这条线路把 TCP 7844 挡了 # QUIC 走 UDP 7844 -> 能连上(虽然偶尔抖) # 所以**只能用 QUIC**,之前的 502/530 是线路抖动,不是协议选错。 # # 抗抖动调优: # 1. --ha-connections 4 同时保持 4 条到边缘的连接(默认值,显式写上) # 2. --retries 5 连边缘失败时多重试 # 3. 中转的长轮询从 25 秒降到 15 秒 # 长连接更容易被抖动打断;短一点反而更稳, # 而且断了一条只影响 15 秒的请求,不是 25 秒。 set -u RELAY_DIR=/root/lanremote-relay echo "===== 1. 写回 QUIC + 调优参数 =====" cat > /etc/systemd/system/lanremote-tunnel.service < 15 秒 =====" UNIT=/etc/systemd/system/lanremote-relay.service if grep -q 'RELAY_POLL' "$UNIT"; then sed -i 's/Environment=RELAY_POLL=.*/Environment=RELAY_POLL=15/' "$UNIT" else sed -i '/Environment=RELAY_DATA/a Environment=RELAY_POLL=15' "$UNIT" fi grep 'RELAY_POLL' "$UNIT" | sed 's/^/ /' echo echo "===== 3. 重启 =====" systemctl stop lanremote-tunnel 2>/dev/null || true pkill -f cloudflared 2>/dev/null || true sleep 3 rm -f "$RELAY_DIR/tunnel.log" systemctl daemon-reload systemctl restart lanremote-relay sleep 3 systemctl start lanremote-tunnel sleep 30 echo " 中转: $(systemctl is-active lanremote-relay)" echo " 隧道: $(systemctl is-active lanremote-tunnel)" echo echo " 注册的连接:" grep -c 'Registered tunnel connection' "$RELAY_DIR/tunnel.log" 2>/dev/null | sed 's/^/ /' grep -oE 'protocol=[a-z0-9]+' "$RELAY_DIR/tunnel.log" 2>/dev/null | sort -u | sed 's/^/ /' echo echo "===== 4. 连打 15 次看成功率 =====" OK=0 for i in $(seq 1 15); do C=$(timeout 15 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)); MARK="✓"; } || MARK="✗" printf " %2d: %s HTTP %s\n" "$i" "$MARK" "${C:-超时}" sleep 2 done echo echo " 成功 $OK / 15" if [ "$OK" -ge 13 ]; then echo " ✓ 稳" elif [ "$OK" -ge 8 ]; then echo " ~ 还行,有抖动但可用" else echo " ✗ 还是抖" fi echo echo "===== 5. 内存 =====" free -m | awk 'NR==2{printf " 已用 %s MB / 可用 %s MB\n", $3, $7}'