Files
ljwx-health/docker-compose-p0-dev.yml
T
brunoandClaude 5f90c88c63 feat: 添加K8s P0监控完整部署配置
## 新增K8s配置文件

**Prometheus Operator集成**:
- servicemonitor.yml: 自动发现ljwx-boot服务,30秒采集间隔
- prometheusrule.yml: 18条告警规则,覆盖P0-3/P0-4所有场景
- grafana-dashboard-configmap.yml: Dashboard导入配置

**应用配置**:
- configmap.yml: 添加P0-3 Redis去重和P0-4缓存失效配置
- application.yml: 更新P0功能配置和Actuator暴露设置

**部署工具**:
- deploy-p0.sh: 一键部署脚本,支持dry-run和健康检查
- P0-K8S-DEPLOYMENT.md: 完整K8s部署指南(18KB)

## Docker Compose开发环境

**混合模式配置**:
- docker-compose-p0-dev.yml: 基础设施Docker化(MySQL/Redis/Prometheus/Grafana)
- prometheus-p0-dev.yml: 使用host.docker.internal访问本地ljwx-boot
- .env.p0: 环境变量配置模板
- verify-p0-dev.sh: 开发环境验证脚本

**完整模式配置**:
- docker-compose-p0.yml: 包含ljwx-boot在内的完整Docker部署
- prometheus-p0.yml: Docker网络内部服务发现

## 文档

**快速开始指南**:
- K8S-P0-QUICK-START.md: K8s部署5分钟快速指南
- P0-DEV-QUICK-START.md: 本地开发环境快速启动指南

**监控Dashboard**:
- grafana-dashboard-p0.json: 修复Dashboard JSON格式问题

## 核心功能

✅ **P0-3 Redis去重**: 分布式去重,24小时TTL
✅ **P0-4 缓存失效**: 事件驱动自动失效,1秒延迟
✅ **完整监控**: 14个Grafana面板,18条告警规则
✅ **多环境支持**: 本地开发、Docker Compose、K8s生产环境

## 告警规则(6组18条)

1. 服务可用性 (2条): 服务不可用、高错误率
2. P0-3 Redis去重 (3条): Redis连接失败、内存告警、Key激增
3. P0-4 缓存失效 (3条): 功能禁用、失败率高、响应慢
4. JVM资源 (2条): 内存不足、GC时间长
5. 数据库连接池 (2条): 连接池耗尽、无空闲连接
6. 应用性能 (2条): API响应慢、并发数高
7. Pod资源 (3条): CPU/内存高、频繁重启

## 部署方式

**K8s生产环境**:
```bash
cd ljwx-boot/k8s
./deploy-p0.sh
```

**本地开发环境**:
```bash
docker-compose -f docker-compose-p0-dev.yml up -d
./ljwx-boot/run-local.sh
```

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

Co-Authored-By: Claude <[email protected]>
2025-12-15 21:50:13 +08:00

190 lines
6.1 KiB
YAML

# ============================================================================
# P0 开发环境 Docker Compose 配置
# 用途: 启动基础设施和监控组件,业务应用(ljwx-boot, ljwx-admin)在本地运行
# 优势: 代码修改无需重新构建镜像,启动快速,方便调试
# ============================================================================
version: '3.8'
networks:
ljwx-network:
driver: bridge
volumes:
mysql_data:
redis_data:
prometheus_data:
grafana_data:
services:
# ============================================================================
# 基础设施服务
# ============================================================================
# MySQL 数据库
ljwx-mysql:
image: mysql:8.0
container_name: ljwx-mysql
environment:
- MYSQL_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD:-123456}
- MYSQL_DATABASE=${MYSQL_DATABASE:-test}
- TZ=${TZ:-Asia/Shanghai}
volumes:
- mysql_data:/var/lib/mysql
- ./sql:/docker-entrypoint-initdb.d:ro
ports:
- "${MYSQL_PORT:-3306}:3306"
networks:
- ljwx-network
restart: unless-stopped
healthcheck:
test: ["CMD", "mysqladmin", "ping", "-h", "localhost", "-u", "root", "-p${MYSQL_ROOT_PASSWORD:-123456}"]
interval: 10s
timeout: 5s
retries: 5
start_period: 30s
command: --default-authentication-plugin=mysql_native_password --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci
# Redis 缓存 (用于去重和缓存)
ljwx-redis:
image: redis:7-alpine
container_name: ljwx-redis
command: >
redis-server
--requirepass ${REDIS_PASSWORD:-123456}
--maxmemory ${REDIS_MAXMEMORY:-2gb}
--maxmemory-policy allkeys-lru
--appendonly yes
volumes:
- redis_data:/data
ports:
- "${REDIS_PORT:-6379}:6379"
networks:
- ljwx-network
restart: unless-stopped
healthcheck:
test: ["CMD", "redis-cli", "-a", "${REDIS_PASSWORD:-123456}", "ping"]
interval: 10s
timeout: 3s
retries: 5
# Redis Exporter (导出Redis指标到Prometheus)
redis-exporter:
image: oliver006/redis_exporter:latest
container_name: redis-exporter
command:
- '--redis.addr=ljwx-redis:6379'
- '--redis.password=${REDIS_PASSWORD:-123456}'
ports:
- "${REDIS_EXPORTER_PORT:-9121}:9121"
networks:
- ljwx-network
depends_on:
ljwx-redis:
condition: service_healthy
restart: unless-stopped
# ============================================================================
# 监控系统服务
# ============================================================================
# Prometheus 指标收集和存储
prometheus:
image: prom/prometheus:latest
container_name: prometheus
volumes:
- ./ljwx-boot/monitoring/prometheus-p0-dev.yml:/etc/prometheus/prometheus.yml:ro
- ./ljwx-boot/monitoring/prometheus-alerts-p0.yml:/etc/prometheus/alerts/p0-alerts.yml:ro
- prometheus_data:/prometheus
command:
- '--config.file=/etc/prometheus/prometheus.yml'
- '--storage.tsdb.path=/prometheus'
- '--web.console.libraries=/usr/share/prometheus/console_libraries'
- '--web.console.templates=/usr/share/prometheus/consoles'
- '--web.enable-lifecycle'
- '--storage.tsdb.retention.time=30d'
ports:
- "${PROMETHEUS_PORT:-9090}:9090"
networks:
- ljwx-network
extra_hosts:
- "host.docker.internal:host-gateway"
depends_on:
redis-exporter:
condition: service_started
restart: unless-stopped
healthcheck:
test: ["CMD", "wget", "-q", "--spider", "http://localhost:9090/-/healthy"]
interval: 30s
timeout: 10s
retries: 3
# Grafana 可视化面板
grafana:
image: grafana/grafana:latest
container_name: grafana
volumes:
- ./ljwx-boot/monitoring/grafana/provisioning:/etc/grafana/provisioning:ro
- ./ljwx-boot/monitoring:/var/lib/grafana/dashboards:ro
- grafana_data:/var/lib/grafana
environment:
- GF_SECURITY_ADMIN_USER=${GRAFANA_ADMIN_USER:-admin}
- GF_SECURITY_ADMIN_PASSWORD=${GRAFANA_ADMIN_PASSWORD:-admin123}
- GF_USERS_ALLOW_SIGN_UP=false
- GF_SERVER_ROOT_URL=http://localhost:${GRAFANA_PORT:-3000}
- GF_INSTALL_PLUGINS=grafana-piechart-panel
- TZ=${TZ:-Asia/Shanghai}
ports:
- "${GRAFANA_PORT:-3000}:3000"
networks:
- ljwx-network
depends_on:
prometheus:
condition: service_healthy
restart: unless-stopped
# ============================================================================
# 使用说明
# ============================================================================
#
# 1. 启动基础设施和监控:
# docker-compose -f docker-compose-p0-dev.yml up -d
#
# 2. 启动本地业务应用:
# # 启动后端 (在 ljwx-boot 目录)
# cd ljwx-boot && ./run-local.sh
#
# # 启动前端 (在 ljwx-admin 目录)
# cd ljwx-admin && pnpm dev
#
# 3. 查看服务状态:
# docker-compose -f docker-compose-p0-dev.yml ps
#
# 4. 查看服务日志:
# docker-compose -f docker-compose-p0-dev.yml logs -f [service-name]
#
# 5. 停止所有服务:
# docker-compose -f docker-compose-p0-dev.yml down
#
# ============================================================================
# 服务访问地址 (开发环境)
# ============================================================================
#
# 业务应用 (本地运行):
# - ljwx-boot 后端API: http://localhost:9998
# - ljwx-boot API文档: http://localhost:9998/doc.html
# - ljwx-boot 健康检查: http://localhost:9998/actuator/health
# - ljwx-boot Metrics: http://localhost:9998/actuator/prometheus
# - ljwx-admin 前端: http://localhost:3333 (或 5173)
#
# 监控系统 (Docker):
# - Grafana Dashboard: http://localhost:3000 (admin/admin123)
# - Prometheus: http://localhost:9090
# - Prometheus Targets: http://localhost:9090/targets
# - Prometheus 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
#