记录踩过的坑,避免下次重新踩。
| 项 | 值 |
|---|---|
| 主机 | 192.168.4.104 |
| 用户 | root |
| 密码 | 8ik,(OL>(截至 2026-04-27 仍有效) |
| 操作系统 | CentOS 7 |
| systemd 版本 | 219(注意:不是 240+,部分新语法不支持) |
| 默认 Python | /usr/bin/python3 是 3.6,没装
pymysql |
| 实际运行用的 Python | /root/miniconda3/bin/python3 是 3.8,装了
pymysql 1.4.6 |
服务器已配 ~/.ssh/id_ed25519 公钥,从配置过 key
的机器(如 Windows 主机)可以免密 SSH。
新机器接入步骤:
# Windows
ssh-keygen -t ed25519 # 生成 key
ssh-copy-id root@192.168.4.104 # 推上去(要密码 8ik,(OL>)
# 之后 ssh root@192.168.4.104 不再问密码服务由 systemd 管理:
systemctl status suifang # 查看状态
systemctl restart suifang # 重启
systemctl stop suifang # 停止
systemctl start suifang # 启动
journalctl -u suifang -f # 看实时日志重启后自动恢复(Restart=on-failure +
WantedBy=multi-user.target)。
/usr/bin/python3 是 3.6,没装
pymysql/root/miniconda3/bin/python3 是 3.8,装了 pymysql
1.4.6ExecStart=python3 ... 会找系统 python,启动失败ExecStart 写绝对路径
/root/miniconda3/bin/python3StandardOutput=append:/...append:/path 语法是 systemd 240+
才有/bin/sh -c '... >> log 2>&1'
包一层做重定向exec 替换 shell 进程,否则 systemd 管理的是 sh
而不是 python最终 unit 文件见 scripts/suifang.service。
仓库里有一键部署脚本:
bash scripts/redeploy.sh # 走 SSH key(默认)
bash scripts/redeploy.sh "8ik,(OL>" # 用密码(兜底)脚本会:
health_server.pyscripts/health_server.pyscripts/suifang.servicesystemctl daemon-reload && enable && restartcurl http://localhost:3000/api/status# 服务器内验证
curl http://localhost:3000/api/status
# 期望: {"status":"running","mysql":"connected","total_devices":12,...}
# 外网验证(经 nginx 反代)
curl https://dc.ncrc.org.cn/api2/api/statusWindows 主机(VPN 客户端)─── 内网路由 ───> 192.168.4.104:22 (SSH)
↓
/opt/suifang/health_server.py
↓ (TCP 3306)
192.168.4.174 (六元 MySQL h6dp_suifang)
外网用户 ──HTTPS──> dc.ncrc.org.cn ──nginx 反代──> 192.168.4.104:3000
注意:WSL2 默认网络模式不共享 Windows VPN tunnel——WSL 这边 SSH 不到 192.168.4.104。 所有部署操作必须在 Windows PowerShell(或装了 git-bash 的 Windows)下完成,不要在 WSL 里跑 redeploy.sh。
| 现象 | 原因 | 解决 |
|---|---|---|
dc.ncrc.org.cn/api2/api/status 返回 502 |
suifang.service 没起来 | systemctl restart suifang |
mysql: disconnected |
192.168.4.174 不通 | 联系六元国锋哥,他那边的网络/MySQL 问题 |
systemctl restart suifang 后还是失败 |
Python 路径或语法错 | journalctl -u suifang -n 50 |
systemctl start suifang 报 unit not found |
未 daemon-reload | systemctl daemon-reload && systemctl enable suifang |
| WSL 里 SSH timeout | WSL2 网络限制 | 切到 PowerShell 操作;或改 WSL networkingMode=mirrored |