Files
ykxmz/_build/fix_tunnel_dep.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.7 KiB
Bash

#!/bin/bash
# 修:重启中转会连带把隧道停掉,而且不会自己起来。
#
# 原因:
# 隧道的 unit 里写了
# Requires=lanremote-relay.service
# Requires 是**双向**的 —— 被依赖的服务一停,依赖它的也会被停。
# 于是重启中转时隧道被停,而没有任何东西会再把它拉起来,
# 公网入口就一直 530。
#
# 修法:
# 改成 Wants= + After=
# Wants 只表示"希望它也起来",单向,不会因为对方停了而停
# After 只表示启动顺序
# 这样中转重启时隧道继续跑(中间那一两秒会 502,随后自动恢复),
# 隧道的 Restart=always 也能管住自己的进程。
set -u
UNIT=/etc/systemd/system/lanremote-tunnel.service
echo "===== 1. 改之前 ====="
grep -E '^(Requires|Wants|After|Description)' "$UNIT" | sed 's/^/ /'
echo
echo "===== 2. 改成单向依赖 ====="
python3 - <<'PY'
from pathlib import Path
path = Path("/etc/systemd/system/lanremote-tunnel.service")
text = path.read_text()
text = text.replace("Requires=lanremote-relay.service\n", "")
if "Wants=network-online.target lanremote-relay.service" not in text:
text = text.replace("Wants=network-online.target",
"Wants=network-online.target lanremote-relay.service")
if "After=network-online.target lanremote-relay.service" not in text:
text = text.replace(
"After=network-online.target",
"After=network-online.target lanremote-relay.service")
# 补一句说明,免得以后有人又改回去
if "# 注意:这里用 Wants 不用 Requires" not in text:
text = text.replace(
"[Unit]\n",
"[Unit]\n# 注意:这里用 Wants 不用 Requires。\n"
"# Requires 是双向的 —— 重启中转会把隧道一起停掉,\n"
"# 而且没有东西会再把它拉起来,公网入口就一直 530。\n", 1)
path.write_text(text)
print(" 已改")
PY
echo
echo "===== 3. 改之后 ====="
grep -E '^(Requires|Wants|After)' "$UNIT" | sed 's/^/ /'
echo
echo "===== 4. 重新加载并启动 ====="
systemctl daemon-reload
systemctl restart lanremote-tunnel
sleep 35
echo " 隧道: $(systemctl is-active lanremote-tunnel)"
echo " 中转: $(systemctl is-active lanremote-relay)"
echo
echo " 已注册连接: $(grep -c 'Registered tunnel connection' /root/lanremote-relay/tunnel.log 2>/dev/null || echo 0)"
echo
echo "===== 5. 验证:重启中转,隧道应该活着 ====="
BEFORE=$(systemctl is-active lanremote-tunnel)
systemctl restart lanremote-relay
sleep 8
AFTER=$(systemctl is-active lanremote-tunnel)
echo " 重启中转前隧道: $BEFORE"
echo " 重启中转后隧道: $AFTER"
if [ "$AFTER" = "active" ]; then
echo " ✓ 修好了 —— 中转重启不再连带停掉隧道"
else
echo " ✗ 还是被连带停掉了"
fi
echo
echo "===== 6. 公网可达性(连打 10 次)====="
sleep 20
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' \
https://relay.xxmxxs.top/v1/health 2>/dev/null)
[ "$C" = "200" ] && { OK=$((OK + 1)); M="✓"; } || M="✗"
printf " %2d: %s HTTP %s\n" "$i" "$M" "${C:-超时}"
sleep 2
done
echo " 成功 $OK / 10"
echo
echo "===== 7. 最终状态 ====="
for s in lanremote-relay lanremote-tunnel lanremote-watchdog.timer; do
printf " %-30s %-9s %s\n" "$s" \
"$(systemctl is-active $s 2>/dev/null)" \
"$(systemctl is-enabled $s 2>/dev/null)"
done
echo
echo " 公网地址: $(cat /root/lanremote-relay/public_url.txt 2>/dev/null)"
echo " 绑定数: $(python3 -c 'import json;print(len(json.load(open(\"/root/lanremote-relay/data/relay_state.json\")).get(\"codes\",[])))' 2>/dev/null)"