mirror of
https://github.com/Yuyi-Oak/BlueArchiveToolkit.git
synced 2026-07-22 06:35:16 +08:00
93 lines
2.7 KiB
YAML
93 lines
2.7 KiB
YAML
# 远程数据库服务器 Docker Compose 配置
|
|
# 用于在裸金属服务器上部署 PostgreSQL 和 Redis
|
|
#
|
|
# 部署步骤:
|
|
# 1. 将此文件和相关配置上传到远程服务器
|
|
# 2. 复制 .env.example 为 .env 并配置密码
|
|
# 3. 运行:docker compose -f docker-compose.remote-db.yml up -d
|
|
# 4. 确保防火墙开放 5432 和 6379 端口
|
|
|
|
version: '3.9'
|
|
|
|
services:
|
|
# PostgreSQL 数据库
|
|
postgres:
|
|
image: postgres:16-alpine
|
|
container_name: bat-postgres
|
|
environment:
|
|
POSTGRES_DB: bluearchive_toolkit
|
|
POSTGRES_USER: ${REMOTE_DB_POSTGRES_USER}
|
|
POSTGRES_PASSWORD: ${REMOTE_DB_POSTGRES_PASSWORD}
|
|
POSTGRES_INITDB_ARGS: "-E UTF8 --locale=C"
|
|
ports:
|
|
- "0.0.0.0:5432:5432" # 监听所有网络接口
|
|
volumes:
|
|
- postgres_data:/var/lib/postgresql/data
|
|
- ./postgres-init:/docker-entrypoint-initdb.d
|
|
- ./pg_hba.conf:/var/lib/postgresql/data/pg_hba.conf
|
|
command: postgres -c hba_file=/var/lib/postgresql/data/pg_hba.conf -c max_connections=200 -c shared_buffers=512MB
|
|
healthcheck:
|
|
test: ["CMD-SHELL", "pg_isready -U ${REMOTE_DB_POSTGRES_USER} -d bluearchive_toolkit"]
|
|
interval: 10s
|
|
timeout: 5s
|
|
retries: 5
|
|
restart: always
|
|
logging:
|
|
driver: "json-file"
|
|
options:
|
|
max-size: "100m"
|
|
max-file: "10"
|
|
|
|
# Redis 缓存
|
|
redis:
|
|
image: redis:7-alpine
|
|
container_name: bat-redis
|
|
command: redis-server /usr/local/etc/redis/redis.conf
|
|
ports:
|
|
- "0.0.0.0:6379:6379" # 监听所有网络接口
|
|
volumes:
|
|
- redis_data:/data
|
|
- ./redis-remote.conf:/usr/local/etc/redis/redis.conf
|
|
healthcheck:
|
|
test: ["CMD", "redis-cli", "-a", "${REMOTE_DB_REDIS_PASSWORD}", "ping"]
|
|
interval: 10s
|
|
timeout: 5s
|
|
retries: 5
|
|
restart: always
|
|
logging:
|
|
driver: "json-file"
|
|
options:
|
|
max-size: "100m"
|
|
max-file: "10"
|
|
|
|
# 数据库备份服务(可选)
|
|
backup:
|
|
image: postgres:16-alpine
|
|
container_name: bat-backup
|
|
profiles: ["backup"]
|
|
environment:
|
|
POSTGRES_HOST: postgres
|
|
POSTGRES_DB: bluearchive_toolkit
|
|
POSTGRES_USER: ${REMOTE_DB_POSTGRES_USER}
|
|
POSTGRES_PASSWORD: ${REMOTE_DB_POSTGRES_PASSWORD}
|
|
volumes:
|
|
- ./backups:/backups
|
|
- ./backup-script.sh:/backup-script.sh
|
|
entrypoint: /bin/sh -c "while true; do sh /backup-script.sh; sleep 86400; done"
|
|
depends_on:
|
|
- postgres
|
|
restart: unless-stopped
|
|
|
|
volumes:
|
|
postgres_data:
|
|
driver: local
|
|
redis_data:
|
|
driver: local
|
|
|
|
# 安全提示:
|
|
# 1. 使用强密码
|
|
# 2. 配置防火墙规则,只允许信任的 IP 访问
|
|
# 3. 启用 SSL/TLS 连接
|
|
# 4. 定期备份数据
|
|
# 5. 监控资源使用和访问日志
|