chore(docker): tune production stack for 2C8G hosts
Nexus CI/CD / test (push) Waiting to run
Nexus CI/CD / deploy (push) Blocked by required conditions
Nexus Pre-commit Checks / quick-check (push) Waiting to run

Add mysql-prod-2c8g.cnf, container mem/cpu limits, Redis maxmemory,
and default Nexus pool 30/20 for 8GiB 1Panel deployments.
This commit is contained in:
Nexus Deploy
2026-06-05 22:44:06 +08:00
parent 2f67e9e2b9
commit bfda70bbe7
6 changed files with 89 additions and 1 deletions
+4
View File
@@ -13,5 +13,9 @@ NEXUS_ENCRYPTION_KEY=
NEXUS_CORS_ORIGINS=https://api.synaglobal.vip
NEXUS_API_BASE_URL=https://api.synaglobal.vip
# 2 vCPU / 8 GiB host (matches docker/mysql-prod-2c8g.cnf + compose limits)
NEXUS_DB_POOL_SIZE=30
NEXUS_DB_MAX_OVERFLOW=20
# Optional
# NEXUS_PUBLISH_PORT=8600
+1
View File
@@ -62,6 +62,7 @@ docker compose -f docker/docker-compose.prod.yml --env-file docker/.env.prod up
- 镜像:`Dockerfile.prod`(含 `npm ci` + `vite build`
- 仅绑定 `127.0.0.1:8600`OpenResty 反代见 `deploy/1panel/openresty-nexus.conf.example`
- **2C8G 调优**`docker/mysql-prod-2c8g.cnf`buffer pool 1G、`max_connections=120`+ 容器 `mem_limit` + `NEXUS_DB_POOL_SIZE=30`
- 完整迁移步骤:`docs/design/plans/2026-06-04-1panel-docker-production.md`
详见 `docs/design/specs/2026-06-03-docker-design.md`
+19 -1
View File
@@ -1,4 +1,6 @@
# Nexus 6.0 — production Compose (1Panel / bare Docker host)
# Tuned for 2 vCPU / 8 GiB — see docker/mysql-prod-2c8g.cnf
#
# Usage:
# cp docker/.env.prod.example docker/.env.prod # fill secrets from Baota .env
# docker compose -f docker/docker-compose.prod.yml --env-file docker/.env.prod up -d --build
@@ -18,6 +20,9 @@ services:
MYSQL_PASSWORD: ${MYSQL_PASSWORD:?set MYSQL_PASSWORD}
volumes:
- mysql-data:/var/lib/mysql
- ./mysql-prod-2c8g.cnf:/etc/mysql/conf.d/99-nexus-2c8g.cnf:ro
mem_limit: 2g
cpus: 1.5
healthcheck:
test: ["CMD-SHELL", "mysqladmin ping -h 127.0.0.1 -uroot -p\"$$MYSQL_ROOT_PASSWORD\" || exit 1"]
interval: 10s
@@ -30,9 +35,18 @@ services:
redis:
image: redis:7-alpine
restart: unless-stopped
command: ["redis-server", "--appendonly", "yes"]
command:
- redis-server
- --appendonly
- "yes"
- --maxmemory
- 256mb
- --maxmemory-policy
- allkeys-lru
volumes:
- redis-data:/data
mem_limit: 384m
cpus: 0.5
healthcheck:
test: ["CMD", "redis-cli", "ping"]
interval: 10s
@@ -70,9 +84,13 @@ services:
NEXUS_API_KEY: ${NEXUS_API_KEY:?set NEXUS_API_KEY}
NEXUS_ENCRYPTION_KEY: ${NEXUS_ENCRYPTION_KEY:-}
NEXUS_API_BASE_URL: ${NEXUS_API_BASE_URL:?set NEXUS_API_BASE_URL}
NEXUS_DB_POOL_SIZE: ${NEXUS_DB_POOL_SIZE:-30}
NEXUS_DB_MAX_OVERFLOW: ${NEXUS_DB_MAX_OVERFLOW:-20}
volumes:
- nexus-state:/var/lib/nexus
- nexus-web-data:/app/web/data
mem_limit: 2g
cpus: 1.5
healthcheck:
test: ["CMD", "curl", "-sf", "http://127.0.0.1:8600/health"]
interval: 30s
+25
View File
@@ -0,0 +1,25 @@
# MySQL 8.4 — Nexus production tuning for 2 vCPU / 8 GiB host
# Mounted by docker/docker-compose.prod.yml (see docs/design/plans/2026-06-04-1panel-docker-production.md)
[mysqld]
character-set-server = utf8mb4
collation-server = utf8mb4_unicode_ci
# ~1 GiB for InnoDB (leave RAM for Nexus, Redis, 1Panel, OS)
innodb_buffer_pool_size = 1024M
innodb_log_file_size = 256M
# Nexus async pool default 30+20; leave headroom for admin/migrations
max_connections = 120
# 2 vCPU: avoid aggressive IO threads
innodb_read_io_threads = 4
innodb_write_io_threads = 4
# Sensible defaults on small VMs
table_open_cache = 2000
tmp_table_size = 64M
max_heap_table_size = 64M
[client]
default-character-set = utf8mb4
@@ -0,0 +1,28 @@
# Changelog — 生产 Compose 2C8G 调优
## 摘要
为 2 核 8G 单机(1Panel + Docker Compose)增加 MySQL/Redis/Nexus 内存与连接池调优。
## 变更
| 文件 | 说明 |
|------|------|
| `docker/mysql-prod-2c8g.cnf` | `innodb_buffer_pool_size=1024M``max_connections=120` |
| `docker/docker-compose.prod.yml` | 挂载 cnf`mem_limit`/`cpus`Redis `maxmemory 256mb`;默认 pool 30/20 |
| `docker/.env.prod.example` | 文档化 `NEXUS_DB_POOL_SIZE` / `OVERFLOW` |
| `docker/README.md` | 2C8G 说明 |
| `docs/design/plans/2026-06-04-1panel-docker-production.md` | 资源预算表 |
## 验证
```bash
docker compose -f docker/docker-compose.prod.yml config
# 启动后:
docker compose -f docker/docker-compose.prod.yml exec mysql \
mysql -uroot -p"$MYSQL_ROOT_PASSWORD" -e "SHOW VARIABLES LIKE 'innodb_buffer_pool_size';"
```
## 回滚
移除 `mysql-prod-2c8g.cnf` 挂载并 `compose up`;或恢复默认 pool 160/120(不推荐 8G 机)。
@@ -253,6 +253,18 @@ docker compose -f docker/docker-compose.prod.yml exec mysql \
| Nexus 端口 | `8600:8600` | `127.0.0.1:8600:8600` |
| env 文件 | `docker/.env` | `docker/.env.prod` |
| 副本数 | 1 | **1**(后台任务 primary worker,勿随意扩多实例) |
| **2C8G 调优** | 无 | `mysql-prod-2c8g.cnf` + 容器内存上限 + pool 30/20 |
### 2C8G 资源预算(约)
| 组件 | 上限 |
|------|------|
| MySQL | 2G 容器 / `innodb_buffer_pool_size=1024M` |
| Redis | 384M 容器 / `maxmemory 256mb` |
| Nexus | 2G 容器 |
| 1Panel + OS | 其余 ~3G |
`docker/.env.prod` 建议包含:`NEXUS_DB_POOL_SIZE=30``NEXUS_DB_MAX_OVERFLOW=20`
---