mirror of
https://gitee.com/xmz7891/ykxmz.git
synced 2026-10-18 23:00:44 +00:00
琚帶绔?- 淇 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 + 鍙岃繛鎺? 鏂囨。 - 璁稿彲鍗忚 / 瀹夎鍓嶅繀璇?/ 瀹夎鍚庨』鐭ワ紙浣滆€咃細灏忛害瀛愶級
82 lines
2.6 KiB
Bash
82 lines
2.6 KiB
Bash
#!/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
|