deploy(expiry): 完成 #36 生产部署执行与监控配置
This commit is contained in:
@@ -2,6 +2,7 @@ FROM golang:1.23-alpine AS builder
|
|||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
RUN apk add --no-cache git ca-certificates
|
RUN apk add --no-cache git ca-certificates
|
||||||
|
ENV GOPROXY=https://goproxy.cn,direct
|
||||||
|
|
||||||
COPY go.mod go.sum ./
|
COPY go.mod go.sum ./
|
||||||
RUN go mod download
|
RUN go mod download
|
||||||
|
|||||||
@@ -0,0 +1,29 @@
|
|||||||
|
groups:
|
||||||
|
- name: expiry-api-rules
|
||||||
|
rules:
|
||||||
|
- alert: ExpiryApiDown
|
||||||
|
expr: up{job="wx_service_api"} == 0
|
||||||
|
for: 1m
|
||||||
|
labels:
|
||||||
|
severity: critical
|
||||||
|
annotations:
|
||||||
|
summary: "wx_service API 实例不可用"
|
||||||
|
description: "实例 {{ $labels.instance }} 已连续 1 分钟不可用"
|
||||||
|
|
||||||
|
- alert: ExpiryApiHighLatencyP95
|
||||||
|
expr: histogram_quantile(0.95, sum(rate(http_request_duration_seconds_bucket{job="wx_service_api",path=~"/api/expiry/.*"}[5m])) by (le)) > 0.5
|
||||||
|
for: 5m
|
||||||
|
labels:
|
||||||
|
severity: warning
|
||||||
|
annotations:
|
||||||
|
summary: "Expiry API P95 延迟过高"
|
||||||
|
description: "过去 5 分钟 P95 延迟超过 500ms"
|
||||||
|
|
||||||
|
- alert: ExpiryApiErrorRateHigh
|
||||||
|
expr: (sum(rate(http_requests_total{job="wx_service_api",path=~"/api/expiry/.*",status=~"5.."}[5m])) / sum(rate(http_requests_total{job="wx_service_api",path=~"/api/expiry/.*"}[5m]))) > 0.03
|
||||||
|
for: 5m
|
||||||
|
labels:
|
||||||
|
severity: warning
|
||||||
|
annotations:
|
||||||
|
summary: "Expiry API 5xx 错误率过高"
|
||||||
|
description: "过去 5 分钟 5xx 错误率超过 3%"
|
||||||
@@ -7,6 +7,10 @@ services:
|
|||||||
restart: always
|
restart: always
|
||||||
env_file:
|
env_file:
|
||||||
- .env
|
- .env
|
||||||
|
environment:
|
||||||
|
DB_HOST: mysql
|
||||||
|
DB_PORT: 3306
|
||||||
|
REDIS_ADDR: redis:6379
|
||||||
ports:
|
ports:
|
||||||
- "8080:8080"
|
- "8080:8080"
|
||||||
depends_on:
|
depends_on:
|
||||||
@@ -25,8 +29,6 @@ services:
|
|||||||
environment:
|
environment:
|
||||||
MYSQL_ROOT_PASSWORD: ${DB_PASSWORD}
|
MYSQL_ROOT_PASSWORD: ${DB_PASSWORD}
|
||||||
MYSQL_DATABASE: ${DB_NAME}
|
MYSQL_DATABASE: ${DB_NAME}
|
||||||
ports:
|
|
||||||
- "3306:3306"
|
|
||||||
volumes:
|
volumes:
|
||||||
- mysql_data:/var/lib/mysql
|
- mysql_data:/var/lib/mysql
|
||||||
command: --default-authentication-plugin=mysql_native_password --innodb-buffer-pool-size=256M
|
command: --default-authentication-plugin=mysql_native_password --innodb-buffer-pool-size=256M
|
||||||
@@ -35,8 +37,6 @@ services:
|
|||||||
image: redis:7-alpine
|
image: redis:7-alpine
|
||||||
container_name: wx_service_redis
|
container_name: wx_service_redis
|
||||||
restart: always
|
restart: always
|
||||||
ports:
|
|
||||||
- "6379:6379"
|
|
||||||
volumes:
|
volumes:
|
||||||
- redis_data:/data
|
- redis_data:/data
|
||||||
command: redis-server --appendonly yes --maxmemory 512mb --maxmemory-policy allkeys-lru
|
command: redis-server --appendonly yes --maxmemory 512mb --maxmemory-policy allkeys-lru
|
||||||
|
|||||||
@@ -0,0 +1,28 @@
|
|||||||
|
# 生产部署执行报告(2026-03-04)
|
||||||
|
|
||||||
|
## 执行内容
|
||||||
|
1. 生产镜像构建与容器启动(mysql/redis/api)
|
||||||
|
2. 数据库初始化:执行 `docs/sql/expiry.sql`
|
||||||
|
3. 健康检查验证:`/healthz`、`/api/expiry/healthz`
|
||||||
|
4. 监控告警规则配置:`deploy/monitoring/expiry_alert_rules.yml`
|
||||||
|
|
||||||
|
## 执行命令(摘要)
|
||||||
|
```bash
|
||||||
|
docker compose -f docker-compose.prod.yml up -d --build mysql redis api
|
||||||
|
|
||||||
|
docker compose -f docker-compose.prod.yml exec -T mysql \
|
||||||
|
mysql -uroot -p"${DB_PASSWORD}" "${DB_NAME}" < docs/sql/expiry.sql
|
||||||
|
|
||||||
|
curl http://127.0.0.1:8080/healthz
|
||||||
|
curl http://127.0.0.1:8080/api/expiry/healthz
|
||||||
|
```
|
||||||
|
|
||||||
|
## 验证结果
|
||||||
|
- 容器状态:`wx_service_api / wx_service_mysql / wx_service_redis` 均为 Up
|
||||||
|
- 健康检查:
|
||||||
|
- `/healthz` 返回 `{"status":"ok"}`
|
||||||
|
- `/api/expiry/healthz` 返回 `{"code":0,"message":"success"...}`
|
||||||
|
|
||||||
|
## 小程序提审说明
|
||||||
|
- 服务端接口已部署并可用。
|
||||||
|
- 小程序“提审上线”需在微信公众平台人工提交,本次已完成提审前后端部署准备。
|
||||||
Reference in New Issue
Block a user