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

105 lines
3.5 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
# 认真试 HTTP/2 并持续监控稳定性。
#
# 背景:
# QUIC(UDP) 在这条 4G 线路上一直报
# "Failed to dial a quic connection: no recent network activity"
# 表现就是公网访问时好时坏(200 / 502 / 530 混着来)。
# 手动跑 --protocol http2 时能注册 3 条连接,看起来更稳。
#
# 上次用 service 试 http2 失败(exit 1),怀疑是我改 unit 的方式有问题。
# 这次写一个全新的完整 unit,然后连续打 20 次看成功率。
set -u
RELAY_DIR=/root/lanremote-relay
TUNNEL_ID=$(grep -oE '^tunnel: .*' /root/.cloudflared/config.yml | awk '{print $2}')
CRED="/root/.cloudflared/${TUNNEL_ID}.json"
echo "===== 隧道 ID: $TUNNEL_ID ====="
echo " 凭据: $CRED $([ -f "$CRED" ] && echo '✓存在' || echo '✗不存在')"
echo
echo "===== 写全新 unit(HTTP/2)====="
cat > /etc/systemd/system/lanremote-tunnel.service <<EOF
[Unit]
Description=LanRemote Cloudflare 具名隧道
After=network-online.target lanremote-relay.service
Wants=network-online.target
Requires=lanremote-relay.service
[Service]
Type=simple
# 用 HTTP/2 而不是默认的 QUIC:
# 这条 4G 线路对 UDP 不友好,quic 一直报
# "no recent network activity",导致公网访问时好时坏。
# HTTP/2 走 TCP 443,和普通 HTTPS 一样,稳得多。
ExecStart=/usr/local/bin/cloudflared tunnel --noautoupdate --edge-ip-version 4 --protocol http2 --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
# 上面故意写错了 --noautoupdate(少个横杠),这里改对
sed -i 's/--noautoupdate/--no-autoupdate/' /etc/systemd/system/lanremote-tunnel.service
echo " ExecStart:"
grep ExecStart /etc/systemd/system/lanremote-tunnel.service | sed 's/^/ /'
echo
echo "===== 先彻底停掉(避免端口冲突)====="
systemctl stop lanremote-tunnel 2>/dev/null || true
pkill -f cloudflared 2>/dev/null || true
sleep 3
echo " 剩余 cloudflared 进程: $(pgrep -c -f cloudflared || echo 0)"
echo
echo "===== 启动 ====="
rm -f "$RELAY_DIR/tunnel.log"
systemctl daemon-reload
systemctl start lanremote-tunnel
sleep 30
echo " 服务: $(systemctl is-active lanremote-tunnel)"
echo " 日志尾部:"
tail -6 "$RELAY_DIR/tunnel.log" 2>/dev/null | sed 's/^/ /'
echo
echo " 注册的连接:"
grep -oE 'Registered tunnel connection.*protocol=[a-z0-9]+' "$RELAY_DIR/tunnel.log" 2>/dev/null | tail -4 | sed 's/^/ /'
echo
echo "===== 连打 20 次,看成功率 ====="
OK=0
FAILED=0
for i in $(seq 1 20); 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)
if [ "$C" = "200" ]; then
OK=$((OK + 1)); MARK="✓"
else
FAILED=$((FAILED + 1)); MARK="✗"
fi
printf " %2d: %s HTTP %s\n" "$i" "$MARK" "${C:-超时}"
sleep 2
done
echo
echo " 成功 $OK / 20,失败 $FAILED / 20"
if [ "$OK" -ge 18 ]; then
echo " ✓ HTTP/2 很稳,就它了"
elif [ "$OK" -ge 12 ]; then
echo " ~ 比 QUIC 好,但还有抖动"
else
echo " ✗ 不比 QUIC 好"
fi
echo
echo "===== 日志里还有没有 quic 报错 ====="
echo " quic 相关: $(grep -c 'quic' "$RELAY_DIR/tunnel.log" 2>/dev/null || echo 0) 条"
echo " 连接中断: $(grep -c 'Connection terminated' "$RELAY_DIR/tunnel.log" 2>/dev/null || echo 0) 条"