mirror of
https://gitee.com/xmz7891/ykxmz.git
synced 2026-10-18 16:00:43 +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 + 鍙岃繛鎺? 鏂囨。 - 璁稿彲鍗忚 / 瀹夎鍓嶅繀璇?/ 瀹夎鍚庨』鐭ワ紙浣滆€咃細灏忛害瀛愶級
99 lines
3.2 KiB
Python
99 lines
3.2 KiB
Python
# -*- coding: utf-8 -*-
|
|
"""把 MTU 调优加进 install.sh(新装也带上)。
|
|
|
|
这是这次找到的真正根因:
|
|
接口 MTU 写 1500,但 4G 路径扛不住 —— ping 实测包 1488 就丢、
|
|
1500 全丢。TLS 握手要发大证书包 -> 被丢 -> 新建连接约 30% 失败。
|
|
|
|
修复:tcp_mtu_probing=1 + MSS 夹 1360(不动接口 MTU,实测降它反而更差)。
|
|
效果:隧道可用率 48%~75% -> 90%~92%。
|
|
"""
|
|
from __future__ import annotations
|
|
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
INSTALL = Path(r"C:\Users\shu\Desktop\deepseekagent\LanRemote\relay"
|
|
r"\install.sh")
|
|
|
|
ANCHOR = 'echo "[4/5]'
|
|
|
|
NEW = '''echo
|
|
echo "[3c] 网络调优(修 MTU —— 这是可用率从 48% 提到 90% 的关键)"
|
|
# 实测:接口 MTU 1500 时,ping 包 1488 就丢、1500 全丢。
|
|
# TLS 握手要发大证书包 -> 被丢 -> 新建连接约 30% 失败。
|
|
# 夹 MSS 到 1360 + 打开路径 MTU 探测之后,可用率 48%~75% -> 90%~92%。
|
|
# 注意:**不要改接口 MTU**,实测降到 1400 反而掉到 50%。
|
|
if [ -f "$SCRIPT_DIR/net-tune.sh" ]; then
|
|
cp -f "$SCRIPT_DIR/net-tune.sh" "$RELAY_DIR/net-tune.sh"
|
|
elif [ -f "$RELAY_DIR/net-tune.sh" ]; then
|
|
: # 已经在位
|
|
fi
|
|
if [ -f "$RELAY_DIR/net-tune.sh" ]; then
|
|
chmod +x "$RELAY_DIR/net-tune.sh"
|
|
|
|
# 内核参数持久化
|
|
cat > /etc/sysctl.d/99-lanremote-mtu.conf <<'MTUEOF'
|
|
# LanRemote: 修路径 MTU 问题。
|
|
# 接口 MTU 1500 时大包会被丢(1488/1500 全丢),导致 TLS 握手约 30% 失败。
|
|
net.ipv4.tcp_mtu_probing = 1
|
|
MTUEOF
|
|
sysctl -p /etc/sysctl.d/99-lanremote-mtu.conf >/dev/null 2>&1
|
|
|
|
# 开机自动夹 MSS
|
|
cat > /etc/systemd/system/lanremote-nettune.service <<NUNIT
|
|
[Unit]
|
|
Description=LanRemote 网络调优(修 MTU:夹 MSS + 路径探测)
|
|
After=network-online.target
|
|
Wants=network-online.target
|
|
Before=lanremote-relay.service lanremote-tunnel.service
|
|
|
|
[Service]
|
|
Type=oneshot
|
|
RemainAfterExit=yes
|
|
ExecStart=$RELAY_DIR/net-tune.sh
|
|
|
|
[Install]
|
|
WantedBy=multi-user.target
|
|
NUNIT
|
|
systemctl daemon-reload
|
|
systemctl enable lanremote-nettune.service >/dev/null 2>&1
|
|
systemctl start lanremote-nettune.service
|
|
sleep 1
|
|
echo " tcp_mtu_probing = $(cat /proc/sys/net/ipv4/tcp_mtu_probing)"
|
|
echo " MSS 规则 $(iptables -t mangle -L -n 2>/dev/null | grep -ci mss) 条"
|
|
echo " 已注册 lanremote-nettune.service(开机自动应用)"
|
|
else
|
|
echo " 跳过:找不到 net-tune.sh"
|
|
fi
|
|
|
|
''' + ANCHOR
|
|
|
|
|
|
def main() -> int:
|
|
text = INSTALL.read_text(encoding="utf-8")
|
|
|
|
if "lanremote-nettune" in text:
|
|
print(" 已经加过")
|
|
return 0
|
|
if ANCHOR not in text:
|
|
print(" [失败] 锚点没找到")
|
|
for index, line in enumerate(text.splitlines(), 1):
|
|
if line.startswith('echo "['):
|
|
print(f" {index}: {line}")
|
|
return 1
|
|
|
|
text = text.replace(ANCHOR, NEW, 1)
|
|
INSTALL.write_text(text, encoding="utf-8", newline="\n")
|
|
raw = INSTALL.read_bytes()
|
|
if b"\r\n" in raw:
|
|
INSTALL.write_bytes(raw.replace(b"\r\n", b"\n"))
|
|
print(" 顺手修了 CRLF")
|
|
|
|
print(" 已加 [3c] 网络调优段")
|
|
return 0
|
|
|
|
|
|
if __name__ == "__main__":
|
|
sys.exit(main())
|