Skip to content
On this page

监控维护

系统监控和日常维护指南。

服务管理

Windows

powershell
# 使用 nssm 管理服务
nssm status GisNodeServer   # 查看状态
nssm restart GisNodeServer  # 重启服务
nssm stop GisNodeServer     # 停止服务
nssm start GisNodeServer    # 启动服务

# 查看进程
tasklist | findstr node.exe

# 强制结束
taskkill /F /IM node.exe

Linux

bash
# 使用 systemd 管理服务
sudo systemctl status gisnode    # 查看状态
sudo systemctl restart gisnode   # 重启服务
sudo systemctl stop gisnode      # 停止服务
sudo systemctl start gisnode     # 启动服务

# 查看日志
sudo journalctl -u gisnode -f   # 实时日志
sudo journalctl -u gisnode --since "1 hour ago"  # 最近1小时

# 使用 PM2 管理
pm2 status      # 查看状态
pm2 logs        # 查看日志
pm2 restart gisnode  # 重启
pm2 monit       # 监控资源

健康检查

手动检查

bash
# 检查 HTTP 服务是否响应
curl -s -o /dev/null -w "%{http_code}" http://localhost:3000/api/health

# 返回 200 表示正常

自动检查脚本

Linux:

bash
#!/bin/bash
# health-check.sh
HEALTH_URL="http://localhost:3000/api/health"
RESPONSE=$(curl -s -o /dev/null -w "%{http_code}" $HEALTH_URL)

if [ $RESPONSE -eq 200 ]; then
    echo "$(date) 系统正常"
else
    echo "$(date) 系统异常,响应码: $RESPONSE"
    # 自动重启
    sudo systemctl restart gisnode
fi

添加到 crontab,每5分钟检查一次:

bash
*/5 * * * * /opt/gisnode/health-check.sh >> /opt/gisnode/logs/health.log

日志管理

日志位置

  • nssm 服务: 在 nssm 配置的日志目录
  • systemd 服务: journalctl -u gisnode
  • PM2 管理: ~/.pm2/logs/
  • 手动运行: 控制台输出

日志分析

bash
# 查看错误
grep ERROR /opt/gisnode/logs/app.log

# 统计 API 调用
grep "GET /api" /opt/gisnode/logs/app.log | wc -l

# 实时监控
tail -f /opt/gisnode/logs/app.log

性能监控

关键指标

指标正常范围告警阈值
CPU< 70%> 80%
内存< 80%> 90%
磁盘< 80%> 90%
响应时间< 500ms> 1000ms

查看系统资源

bash
# CPU 和内存
top -p $(pgrep -f node.exe)

# 磁盘使用
df -h /opt/gisnode
du -sh /opt/gisnode/data/*

# 进程内存
ps aux | grep node.exe

日常维护

每日检查

  • [ ] 检查服务状态
  • [ ] 查看错误日志
  • [ ] 检查磁盘空间
  • [ ] 验证备份完成

每周维护

  • [ ] 清理临时文件
  • [ ] 检查数据增长趋势
  • [ ] 测试备份恢复

每月维护

  • [ ] 清理旧备份
  • [ ] 检查安全日志
  • [ ] 性能分析
  • [ ] 容量规划

清理脚本

Linux:

bash
#!/bin/bash
# cleanup.sh

# 清理临时文件
find /opt/gisnode/data/temp -type f -mtime +7 -delete

# 清理旧备份(保留30天)
find /opt/gisnode/backups -name "*.tar.gz" -mtime +30 -delete

# 清理日志(保留30天)
find /opt/gisnode/logs -name "*.log" -mtime +30 -delete

Windows:

powershell
# cleanup.ps1
# 清理临时文件
Get-ChildItem D:\gisnode\data\temp -Recurse | Where-Object { $_.LastWriteTime -lt (Get-Date).AddDays(-7) } | Remove-Item -Force

# 清理旧备份
Get-ChildItem D:\gisnode\backups -Recurse | Where-Object { $_.LastWriteTime -lt (Get-Date).AddDays(-30) } | Remove-Item -Force

升级更新

当收到新版本发布包时:

  1. 备份数据(重要!)
  2. 停止当前服务
  3. 替换 node.exedist/docs/native/ 等程序文件
  4. 不要替换 data/ 目录和 .env 文件
  5. 启动服务
  6. 验证功能正常

基于 MIT 许可发布