Files
ykxmz/_build/try_ha1.sh
T
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

89 lines
3.0 KiB
Bash
Raw 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
# 当前链路严重退化(18 次断开 / 20 次 quic 错误 / 公网 0/10)。
# 试试 ha-connections=1:少一条并发 QUIC 就少一份争抢。
set -u
RELAY_DIR=/root/lanremote-relay
UNIT=/etc/systemd/system/lanremote-tunnel.service
URL=https://relay.xxmxxs.top
echo "===== 1. 改成 ha=1 ====="
cat > "$UNIT" <<'EOF'
[Unit]
Description=LanRemote Cloudflare 具名隧道
After=network-online.target lanremote-relay.service
Wants=network-online.target lanremote-relay.service
[Service]
Type=simple
# 协议:必须 QUIC(这条线路挡了 HTTP/2 的 TCP 7844)
# 连接数:1
# 实测 4 条并发 QUIC 握手互相挤(只成功 1 条);
# 链路退化时 2 条也会有一条一直失败重试、拖累另一条。
# 1 条最稳。丢冗余换稳定 —— 看门狗会在断的时候重启。
ExecStart=/usr/local/bin/cloudflared tunnel --no-autoupdate --edge-ip-version 4 --ha-connections 1 --retries 5 --config /root/.cloudflared/config.yml run lanremote
Restart=always
RestartSec=5
MemoryMax=128M
StandardOutput=append:/root/lanremote-relay/tunnel.log
StandardError=append:/root/lanremote-relay/tunnel.log
[Install]
WantedBy=multi-user.target
EOF
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 start lanremote-tunnel
echo " 已启动,等 40 秒建连接…"
sleep 40
echo
echo "===== 2. 连接情况 ====="
echo -n " 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 " 注册: $(grep -c 'Registered tunnel connection' $RELAY_DIR/tunnel.log 2>/dev/null || echo 0)"
echo " 断开: $(grep -c 'Connection terminated' $RELAY_DIR/tunnel.log 2>/dev/null || echo 0)"
echo
echo "===== 3. 公网连打 15 次 ====="
OK=0
for i in $(seq 1 15); do
C=$(timeout 20 curl -4 -s -o /dev/null -w '%{http_code}' \
-H 'User-Agent: LanRemote/1.4.0' "$URL/v1/health" 2>/dev/null)
[ "$C" = "200" ] && { OK=$((OK+1)); M="✓"; } || M="✗"
printf " %2d: %s %s\n" "$i" "$M" "${C:-超时}"
sleep 2
done
PCT=$((OK * 100 / 15))
echo " 公网 $OK / 15 ($PCT%)"
echo
echo "===== 4. 再等 60 秒看长稳不稳 ====="
sleep 60
OK2=0
for i in $(seq 1 10); do
C=$(timeout 20 curl -4 -s -o /dev/null -w '%{http_code}' \
-H 'User-Agent: LanRemote/1.4.0' "$URL/v1/health" 2>/dev/null)
[ "$C" = "200" ] && OK2=$((OK2+1))
sleep 3
done
echo " 第二轮 $OK2 / 10"
echo -n " 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 "===== 5. 结论 ====="
echo " ha=1: 第一轮 $OK/15,第二轮 $OK2/10"
if [ "$OK" -ge 12 ] || [ "$OK2" -ge 8 ]; then
echo " ✓ 比 ha=2 好,定 ha=1"
else
echo " ✗ 还是不行 —— 这是链路本身的问题(运营商/信号),"
echo " 不是配置能救的。看门狗会持续重启。"
fi