#!/bin/bash # 查隧道反复重连的根因:内存限制?OOM?DNS 差异? set -u echo "════════ 1. 内存总览 ════════" free -m | sed 's/^/ /' echo echo "════════ 2. 各进程内存占用 ════════" ps aux --sort=-rss 2>/dev/null | head -8 | awk '{printf " %-8s %6s MB %s\n", $1, int($6/1024), $11}' echo echo "════════ 3. 隧道 unit 里的内存限制 ════════" grep -E 'MemoryMax|MemoryHigh|Restart' /etc/systemd/system/lanremote-tunnel.service | sed 's/^/ /' echo " 当前实际用量:" systemctl show lanremote-tunnel -p MemoryCurrent -p MemoryMax --value 2>/dev/null | sed 's/^/ /' echo echo "════════ 4. 有没有被 OOM 杀过 ════════" journalctl -u lanremote-tunnel --since '6 hours ago' --no-pager 2>/dev/null \ | grep -iE 'oom|killed|memory|out of memory' | tail -8 | sed 's/^/ /' echo " dmesg 里的 OOM:" dmesg 2>/dev/null | grep -iE 'oom|killed process' | tail -6 | sed 's/^/ /' echo " (没输出=没被 OOM 杀)" echo echo "════════ 5. 隧道服务重启过几次 ════════" journalctl -u lanremote-tunnel --since '6 hours ago' --no-pager 2>/dev/null \ | grep -cE 'Started|Stopped|Deactivated' | sed 's/^/ 系统层面事件数: /' echo " 最近的启动/停止:" journalctl -u lanremote-tunnel --since '6 hours ago' --no-pager 2>/dev/null \ | grep -E 'Started|Stopped|Deactivated|killed' | tail -8 | sed 's/^/ /' echo echo "════════ 6. 隧道日志里重连的频率 ════════" echo " 最近 6 小时的日志行数: $(wc -l < /root/lanremote-relay/tunnel.log)" for kw in 'Registered tunnel connection' 'Lost connection' 'Retrying connection' 'i/o timeout'; do n=$(tail -3000 /root/lanremote-relay/tunnel.log 2>/dev/null | grep -c "$kw") printf " %-32s %s 次\n" "$kw" "$n" done echo echo "════════ 7. DNS:设备这边解析到哪 ════════" getent hosts relay.xxmxxs.top | sed 's/^/ /' echo " 直接问 1.1.1.1:" nslookup relay.xxmxxs.top 1.1.1.1 2>/dev/null | grep -A2 'Name:' | sed 's/^/ /' echo echo "════════ 8. relay.log 里的错误(最后 15 条)════════" tail -400 /root/lanremote-relay/relay.log 2>/dev/null \ | grep -iE 'error|exception|traceback|broken|reset' | tail -15 | sed 's/^/ /' echo " (没输出=没有明显错误)" echo echo "════════ 9. relay.log 最后 12 行(看它在干什么)════════" tail -12 /root/lanremote-relay/relay.log 2>/dev/null | sed 's/^/ /' echo echo "════════ 10. watchdog 在干什么 ════════" tail -12 /root/lanremote-relay/watchdog.log 2>/dev/null | sed 's/^/ /' echo " watchdog 服务: $(systemctl is-active lanremote-watchdog 2>&1)"