mirror of
https://gitee.com/xmz7891/ykxmz.git
synced 2026-10-18 19:30:42 +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 + 鍙岃繛鎺? 鏂囨。 - 璁稿彲鍗忚 / 瀹夎鍓嶅繀璇?/ 瀹夎鍚庨』鐭ワ紙浣滆€咃細灏忛害瀛愶級
97 lines
3.1 KiB
Bash
97 lines
3.1 KiB
Bash
#!/bin/bash
|
||
# 测试 --region:能不能让 cloudflared 连亚洲边缘而不是美西?
|
||
#
|
||
# 现状:连的是 198.41.x.x,落地 lax01/sjc07(美西),ICMP 199~243ms,
|
||
# 丢包 40%,握手经常超时。
|
||
# cloudflared 有个 --region 参数("Cloudflare Edge region to connect to")。
|
||
# 如果能把落地换到香港/新加坡/东京,延迟和丢包都会好很多。
|
||
set -u
|
||
|
||
URL=https://relay.xxmxxs.top
|
||
RELAY_DIR=/root/lanremote-relay
|
||
BASE="--no-autoupdate --edge-ip-version 4 --retries 5 --config /root/.cloudflared/config.yml run lanremote"
|
||
|
||
try_region() {
|
||
local region="$1"
|
||
local label="$2"
|
||
|
||
systemctl stop lanremote-tunnel 2>/dev/null || true
|
||
pkill -f cloudflared 2>/dev/null || true
|
||
sleep 2
|
||
: > "$RELAY_DIR/tunnel.log"
|
||
|
||
if [ -n "$region" ]; then
|
||
nohup cloudflared tunnel --region "$region" $BASE \
|
||
>> "$RELAY_DIR/tunnel.log" 2>&1 &
|
||
else
|
||
nohup cloudflared tunnel $BASE >> "$RELAY_DIR/tunnel.log" 2>&1 &
|
||
fi
|
||
|
||
sleep 30
|
||
|
||
local conns loc proto
|
||
conns=$(grep -c 'Registered tunnel connection' "$RELAY_DIR/tunnel.log" 2>/dev/null || echo 0)
|
||
loc=$(grep -o 'location=[a-z0-9]*' "$RELAY_DIR/tunnel.log" 2>/dev/null | tail -1)
|
||
proto=$(grep -o 'protocol=[a-z0-9]*' "$RELAY_DIR/tunnel.log" 2>/dev/null | tail -1)
|
||
|
||
printf " %-14s 注册 %-3s %-14s %s\n" "$label" "$conns" "${loc:-?}" "${proto:-?}"
|
||
|
||
if [ "$conns" = "0" ]; then
|
||
echo " 报错:"
|
||
grep -iE 'error|fatal|invalid' "$RELAY_DIR/tunnel.log" 2>/dev/null \
|
||
| tail -2 | sed 's/^/ /'
|
||
fi
|
||
|
||
# 快速探 10 次
|
||
local ok=0
|
||
for i in $(seq 1 10); do
|
||
c=$(timeout 12 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))
|
||
sleep 2
|
||
done
|
||
echo " 公网 $ok/10"
|
||
echo "$label|$ok|${loc:-?}|$conns" >> /root/region_result.txt
|
||
pkill -f cloudflared 2>/dev/null || true
|
||
sleep 2
|
||
}
|
||
|
||
: > /root/region_result.txt
|
||
|
||
echo "===== 各 region 的表现 ====="
|
||
try_region "" "默认(global)"
|
||
try_region "ap" "ap"
|
||
try_region "us" "us"
|
||
|
||
echo
|
||
echo "===== 汇总 ====="
|
||
while IFS='|' read -r label ok loc conns; do
|
||
printf " %-16s 公网 %s/10 落地=%s 注册=%s\n" "$label" "$ok" "$loc" "$conns"
|
||
done < /root/region_result.txt
|
||
|
||
echo
|
||
echo "===== 恢复默认配置 ====="
|
||
cat > /etc/systemd/system/lanremote-tunnel.service <<EOF
|
||
[Unit]
|
||
Description=LanRemote Cloudflare 具名隧道
|
||
After=network-online.target lanremote-relay.service
|
||
Wants=network-online.target lanremote-relay.service
|
||
|
||
[Service]
|
||
Type=simple
|
||
ExecStart=/usr/local/bin/cloudflared tunnel --protocol http2 --ha-connections 2 $BASE
|
||
Restart=always
|
||
RestartSec=5
|
||
MemoryMax=160M
|
||
StandardOutput=append:/root/lanremote-relay/tunnel.log
|
||
StandardError=append:/root/lanremote-relay/tunnel.log
|
||
|
||
[Install]
|
||
WantedBy=multi-user.target
|
||
EOF
|
||
systemctl daemon-reload
|
||
systemctl start lanremote-tunnel
|
||
sleep 30
|
||
echo " 隧道: $(systemctl is-active lanremote-tunnel)"
|
||
echo " 连接数: $(curl -s --max-time 5 http://127.0.0.1:20241/metrics | grep '^cloudflared_tunnel_ha_connections' | awk '{print $2}')"
|