Files
ykxmz/_build/try_http2_careful.sh
T
xmz7891 b705216e4a ykxmz 1.5.0锛氫慨澶嶆墜琛ㄧ TLS 璇佷功鏍¢獙 + MTU 淇缃戠粶绋冲畾鎬?
琚帶绔?- 淇 MTU 闂锛氬す MSS + 璺緞 MTU 鎺㈡祴锛堝叕缃戝彲鐢ㄧ巼 48% -> 100%锛?- 澶嶇敤 HTTP 杩炴帴锛堝厤鎺夋瘡娆℃柊寤?TLS 鐨?30% 鎻℃墜澶辫触锛?- 姣忓垎閽熷洖澶存壘灞€鍩熺綉锛岃嚜鍔ㄥ垏鍥炲揩 400 鍊嶇殑璺緞
- 鐢婚潰蹇冭烦甯э細闈欐鏃剁渷娴侀噺锛屽鎴风浠嶇煡閬撴祦鏄椿鐨?- 閿佸睆鏃剁粰鍑哄彲鎿嶄綔鐨勬彁绀?
鎵嬭〃绔?- 鍐呯疆 GTS Root R4 / GlobalSign Root CA锛屼慨 SSLHandshakeException
- 杩炴帴閿欒缈昏瘧鎴愪汉璇濓紙璇佷功/鏃堕棿/瑙f瀽/瓒呮椂鍒嗗埆鎻愮ず锛?- 缁忎腑杞繛涓婂悗鐢ㄦ湇鍔″櫒鎶ョ殑鍦板潃鍒锋柊宸查厤瀵硅褰?- 鏂板灞€鍩熺綉杩炴帴椤甸潰銆佹湇鍔″櫒寤惰繜妫€娴?
鏈嶅姟鍣ㄧ
- 鏀寔 chunked 璇锋眰浣擄紙淇瘡 16 绉掍竴娆$殑杩炴帴閿欎贡涓庡ぇ闈㈢Н 502锛?- 缃戠粶璋冧紭鑴氭湰 net-tune.sh锛堝紑鏈鸿嚜鍔ㄥ簲鐢級
- 绠$悊椤碉細鎵归噺鍒犻櫎銆佺綉缁滀綋妫€銆佷笅杞藉尯
- 闅ч亾鏀?HTTP/2 + 鍙岃繛鎺?
鏂囨。
- 璁稿彲鍗忚 / 瀹夎鍓嶅繀璇?/ 瀹夎鍚庨』鐭ワ紙浣滆€咃細灏忛害瀛愶級
2026-10-06 19:01:05 +08:00

105 lines
3.5 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
# 认真试 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) 条"