公司服务器 192.168.4.104 运维笔记

记录踩过的坑,避免下次重新踩。

基本信息

主机 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 免密(首次配置)

服务器已配 ~/.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)。

关键坑(写在 scripts/suifang.service 注释里)

坑 1:必须用 miniconda 的 Python,不能用系统 python3

坑 2:CentOS 7 systemd 219 不支持 StandardOutput=append:/...

最终 unit 文件见 scripts/suifang.service

部署流程

仓库里有一键部署脚本:

bash scripts/redeploy.sh                     # 走 SSH key(默认)
bash scripts/redeploy.sh "8ik,(OL>"          # 用密码(兜底)

脚本会:

  1. 备份服务器现有 health_server.py
  2. scp 推送 scripts/health_server.py
  3. scp 推送 scripts/suifang.service
  4. systemctl daemon-reload && enable && restart
  5. 验证 curl 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/status

网络拓扑

Windows 主机(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

联系人