Files
inkreach-official-website/deploy/docker-compose.yml
T
yeuimu 9f856858e2 perf(deploy): 边缘 nginx 承压调优与连接池/PG 参数(P0-2/P0-3)
- 主配置 nginx.conf 进镜像(worker_connections 16384 + rlimit 65536 + gzip
  + 带上游耗时的访问日志):官方默认 1024×4=4096 连接硬顶是 1w 并发第一道墙
- admin.conf:upstream keepalive 64(proxy_http 1.1 + Connection "")、
  /public/ /v2-api/ 限流 50r/s burst 200(429)、代理超时 5s/30s、
  /uploads/ /assets/ 30d 缓存头;admin.v2.conf 的 /v2/h5/ 哈希产物长缓存
- compose:PG 显式参数(statement_timeout=10s/max_connections=200/
  shared_buffers=512MB)、DATABASE_URL connection_limit=50&pool_timeout=3
  (单位秒,勿写毫秒;勿加 statement_cache_size=0)、admin ulimits nofile 65536
- 部署注意:主配置走镜像须 rebuild;PG 参数重启前按全局约束 pg_dump+快照存档
2026-09-03 03:40:28 +08:00

102 lines
3.7 KiB
YAML
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# 单栈部署(2026-09-03 主干收敛后,一切以 v2 为准):
# https://official.inkreach.cc/v2/admin/ -> v2-adminSPA
# https://official.inkreach.cc/v2-api/ -> v2-api(小程序/后台同路径,去前缀转发)
# https://official.inkreach.cc/public/ -> v2-apiH5 历史构建同源 API
# /uploads/ /assets/ -> v2-api;证书续期走 certbot 挂载;边缘入口为 admin 服务。
# v1(旧栈 api+postgres)已退役:容器停用未删,最终档案在 deploy/backups/consolidation-*/。
# v2 数据卷沿用原 deploy-v2 项目卷(external 引用),数据未迁移未改动。
services:
v2-postgres:
image: postgres:16-alpine
restart: unless-stopped
# 性能整改 P0-3plans/refactor/public-capacity-10k-refactor.md):
# - statement_timeout=10s:慢查询不无限期占住连接(池排队由此可控);
# - max_connections=200:为未来 api 副本/同步 worker 预留(单 api 池 50);
# - shared_buffers/effective_cache_size14GB 内存机的工作集调优(数据 ~几十 MB,512MB 充裕)。
# 部署注意(全局约束 §1):改参数需重启容器(秒级中断)——先 pg_dump -Fc + 配置快照
# 落 deploy/backups/<时间戳>/ 再低峰 force-recreate。
command:
[
"postgres",
"-c", "statement_timeout=10000",
"-c", "max_connections=200",
"-c", "shared_buffers=512MB",
"-c", "effective_cache_size=1536MB",
]
environment:
POSTGRES_USER: inkreach
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
POSTGRES_DB: inkreach
volumes:
- v2-pgdata:/var/lib/postgresql/data
healthcheck:
test: ["CMD-SHELL", "pg_isready -U inkreach -d inkreach"]
interval: 10s
timeout: 5s
retries: 10
v2-api:
build:
context: ..
dockerfile: deploy/api.Dockerfile
restart: unless-stopped
depends_on:
v2-postgres:
condition: service_healthy
environment:
NODE_ENV: production
PORT: 3001
# 性能整改 P0-3:池上限 50 < PG max_connections 200(同步/运维连接留余量);
# pool_timeout 单位是秒(Prisma 默认 10)——池耗尽 3s 快速失败而非挂 10s。
# 不要加 statement_cache_size=0pgbouncer 专用,直连禁 prepared statement 反而拖慢)。
DATABASE_URL: postgresql://inkreach:${POSTGRES_PASSWORD}@v2-postgres:5432/inkreach?connection_limit=50&pool_timeout=3
JWT_SECRET: ${JWT_SECRET}
CORS_ORIGINS: "*"
# 激活 product-family 聚合公开读路径
PUBLIC_DETAIL_FROM_FAMILY: "true"
volumes:
- v2-uploads:/app/uploads
v2-admin:
build:
context: ..
dockerfile: deploy/admin.Dockerfile
args:
VITE_API_BASE: /v2-api/
restart: unless-stopped
depends_on:
- v2-api
volumes:
- ./nginx/admin.v2.conf:/etc/nginx/conf.d/default.conf:ro
# 边缘入口:80/443、证书、全站路由与静态资源(/、/admin/、/h5/ 为历史构建,保留展示)
admin:
build:
context: ..
dockerfile: deploy/admin.Dockerfile
args:
VITE_API_BASE: /v2-api/
restart: unless-stopped
depends_on:
- v2-api
ports:
- "80:80"
- "443:443"
# 性能整改 P0-24 worker × 16384 连接 + 上游 keepalive 需要容器 fd 预算匹配
ulimits:
nofile:
soft: 65536
hard: 65536
volumes:
- ./nginx/admin.conf:/etc/nginx/conf.d/default.conf:ro
- ./certbot/www:/var/www/certbot:ro
- ./certbot/acme:/etc/nginx/certs:ro
volumes:
v2-pgdata:
external: true
name: deploy-v2_pgdata
v2-uploads:
external: true
name: deploy-v2_uploads