Files
ykxmz/_build/finalize_http2_ha2.sh
xmz7891 b62ac865ea ykxmz 1.5.0:修复手表端 TLS 证书校验 + MTU 修复网络稳定性
被控端
- 修复 MTU 问题:夹 MSS + 路径 MTU 探测(公网可用率 48% -> 100%)
- 复用 HTTP 连接(免掉每次新建 TLS 的 30% 握手失败)
- 每分钟回头找局域网,自动切回快 400 倍的路径
- 画面心跳帧:静止时省流量,客户端仍知道流是活的
- 锁屏时给出可操作的提示

手表端
- 内置 GTS Root R4 / GlobalSign Root CA,修 SSLHandshakeException
- 连接错误翻译成人话(证书/时间/解析/超时分别提示)
- 经中转连上后用服务器报的地址刷新已配对记录
- 新增局域网连接页面、服务器延迟检测

服务器端
- 支持 chunked 请求体(修每 16 秒一次的连接错乱与大面积 502)
- 网络调优脚本 net-tune.sh(开机自动应用)
- 管理页:批量删除、网络体检、下载区
- 隧道改 HTTP/2 + 双连接

文档
- 许可协议 / 安装前必读 / 安装后须知(作者:小麦子)
2026-10-06 19:01:05 +08:00

74 lines
2.6 KiB
Bash
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/bin/bash
# 定稿:--protocol http2 --ha-connections 2,并验证。
#
# 实测汇总(同一设备、同一时段):
# 协议/连接数 可用率 断开 拨号失败
# QUIC ha=1 48% 16 16
# HTTP2 ha=1 35~65% 0 0
# HTTP2 ha=2 75% 1 0
#
# 结论:HTTP/2 + 两条连接最好。
# - UDP 丢包 -> QUIC 一直超时重连
# - HTTP/2 单条:连接稳,但一条卡住就全卡
# - HTTP/2 两条:一条卡住另一条顶上
set -u
UNIT=/etc/systemd/system/lanremote-tunnel.service
URL=https://relay.xxmxxs.top
RELAY_DIR=/root/lanremote-relay
cat > "$UNIT" <<'EOF'
[Unit]
Description=LanRemote Cloudflare 具名隧道
After=network-online.target lanremote-relay.service
Wants=network-online.target lanremote-relay.service
[Service]
Type=simple
# 协议:HTTP/2(TCP 7844)
# 实测:这条线路丢 UDP 包,QUIC 可用率只有 48% 且频繁重连;
# HTTP/2 稳定得多(断开 0~2 次)。
ExecStart=/usr/local/bin/cloudflared tunnel --no-autoupdate --protocol http2 --edge-ip-version 4 --ha-connections 2 --retries 5 --config /root/.cloudflared/config.yml run lanremote
Restart=always
RestartSec=5
MemoryMax=160M
StandardOutput=append:/root/lanremote-relay/tunnel.log
StandardError=append:/root/lanremote-relay/tunnel.log
[Install]
WantedBy=multi-user.target
EOF
systemctl daemon-reload
systemctl stop lanremote-tunnel 2>/dev/null || true
pkill -f cloudflared 2>/dev/null || true
sleep 3
: > "$RELAY_DIR/tunnel.log"
systemctl start lanremote-tunnel
echo " 已启动(http2 + ha=2),等 40 秒…"
sleep 40
echo
echo " 连接数: $(curl -s --max-time 5 http://127.0.0.1:20241/metrics | grep '^cloudflared_tunnel_ha_connections' | awk '{print $2}')"
echo " 协议: $(grep -o 'protocol=[a-z0-9]*' "$RELAY_DIR/tunnel.log" | tail -1)"
echo
echo "===== 连续探 3 分钟 ====="
ok=0; bad=0
for i in $(seq 1 60); do
code=$(timeout 12 curl -4 -s -o /dev/null -w '%{http_code}' \
-H 'User-Agent: LanRemote/1.4.0' "$URL/v1/health" 2>/dev/null)
code=${code:-000}
if [ "$code" = "200" ]; then ok=$((ok + 1)); else bad=$((bad + 1)); fi
sleep 2
done
echo " 可用 $ok / $((ok + bad)) = $((ok * 100 / (ok + bad)))%"
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) 次"
echo
echo " 对比:"
echo " QUIC ha=1 48%"
echo " HTTP2 ha=1 35~65%"
echo " HTTP2 ha=2 $(printf '%d' $((ok * 100 / (ok + bad))))% <- 现在"