Files
ykxmz/_build/tune_ha.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

82 lines
2.6 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
# 试不同的 cloudflared 连接数,找出这条线路上最稳的配置。
#
# 现状:4 条 ha-connection 的 QUIC 全在超时
# "failed to dial to edge with quic: timeout: handshake did not complete"
# 怀疑:这条 4G 线路对 UDP 有节制 —— 同时建 4 条 QUIC 连接反而更容易被限。
#
# 试:ha=4 / ha=2 / ha=1,各观察一轮。
set -u
RELAY_DIR=/root/lanremote-relay
UNIT=/etc/systemd/system/lanremote-tunnel.service
URL=https://relay.xxmxxs.top
restart_with() {
local ha="$1"
echo "===== 试 ha-connections=$ha ====="
systemctl stop lanremote-tunnel 2>/dev/null || true
pkill -f cloudflared 2>/dev/null || true
sleep 3
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 挡了
ExecStart=/usr/local/bin/cloudflared tunnel --no-autoupdate --edge-ip-version 4 --ha-connections $ha --retries 5 --config /root/.cloudflared/config.yml run lanremote
Restart=always
RestartSec=5
MemoryMax=128M
StandardOutput=append:$RELAY_DIR/tunnel.log
StandardError=append:$RELAY_DIR/tunnel.log
[Install]
WantedBy=multi-user.target
EOF
systemctl daemon-reload
rm -f "$RELAY_DIR/tunnel.log"
systemctl start lanremote-tunnel
echo " 等 50 秒让它建连接…"
sleep 50
local conns
conns=$(grep -c 'Registered tunnel connection' "$RELAY_DIR/tunnel.log" 2>/dev/null || echo 0)
local drops
drops=$(grep -c 'Connection terminated' "$RELAY_DIR/tunnel.log" 2>/dev/null || echo 0)
echo " 已注册 $conns 条,断开 $drops 次"
local ok=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" ] && ok=$((ok + 1))
printf " %2d: HTTP %s\n" "$i" "${C:-超时}"
sleep 2
done
echo " >>> ha=$ha 可用率 $ok/10"
echo "$ha $ok $conns $drops" >> /root/ha_result.txt
echo
}
: > /root/ha_result.txt
restart_with 4
restart_with 2
restart_with 1
echo "===== 汇总 ====="
printf " %-8s %-10s %-10s %s\n" "ha" "可用/10" "已注册" "断开"
while read -r ha ok conns drops; do
printf " %-8s %-10s %-10s %s\n" "$ha" "$ok/10" "$conns" "$drops"
done < /root/ha_result.txt
BEST=$(sort -k2 -nr /root/ha_result.txt | head -1 | awk '{print $1}')
BEST_OK=$(sort -k2 -nr /root/ha_result.txt | head -1 | awk '{print $2}')
echo
echo " 最稳的是 ha-connections=$BEST($BEST_OK/10)"
echo "$BEST" > /root/best_ha.txt