352 lines
9.6 KiB
YAML
Executable File
352 lines
9.6 KiB
YAML
Executable File
# 全量服务部署 (云端/无源码版)
|
|
# 使用方法:
|
|
# 1. 确保已将 docker-compose.cloud.yml, configs/, nginx/, loki/ 目录上传到服务器同一目录
|
|
# 2. 确保 logs/ 目录存在 (mkdir logs)
|
|
# 3. 运行: docker-compose -f docker-compose.cloud.yml up -d
|
|
|
|
services:
|
|
# ----------------------------------------------------
|
|
# 1. 业务后端 (Bindbox Game Backend)
|
|
# ----------------------------------------------------
|
|
bindbox-game:
|
|
image: zfc931912343/bindbox-game:v1.23
|
|
container_name: bindbox-game
|
|
restart: always
|
|
# ports:
|
|
# - "9991:9991" (Internal only)
|
|
volumes:
|
|
# 改为挂载当前目录下的 logs 和 configs
|
|
- ./logs:/app/logs
|
|
- ./configs:/app/configs
|
|
environment:
|
|
- ACTIVE_ENV=pro
|
|
- TZ=Asia/Shanghai
|
|
# MySQL 配置(覆盖编译时的默认值)
|
|
- MYSQL_ADDR=mysql:3306
|
|
- MYSQL_USER=root
|
|
- MYSQL_PASS=bindbox2025kdy
|
|
- MYSQL_NAME=bindbox_game
|
|
# Redis 配置
|
|
- REDIS_ADDR=redis:6379
|
|
networks:
|
|
- bindbox_net
|
|
logging:
|
|
driver: "json-file"
|
|
options:
|
|
max-size: "10m"
|
|
max-file: "3"
|
|
depends_on:
|
|
- mysql
|
|
- redis
|
|
|
|
# ----------------------------------------------------
|
|
# 2. 游戏数据库 (CockroachDB for Nakama)
|
|
# ----------------------------------------------------
|
|
nakama-db:
|
|
image: cockroachdb/cockroach:latest-v23.1
|
|
container_name: nakama-db
|
|
command: start-single-node --insecure --store=attrs=ssd,path=/var/lib/cockroach/ --cache=.25 --max-sql-memory=.25
|
|
restart: always
|
|
volumes:
|
|
- nakama-db-data:/var/lib/cockroach
|
|
healthcheck:
|
|
test: [ "CMD", "curl", "-f", "http://localhost:8080/health?ready=1" ]
|
|
interval: 3s
|
|
timeout: 3s
|
|
retries: 5
|
|
environment:
|
|
- TZ=Asia/Shanghai
|
|
networks:
|
|
- bindbox_net
|
|
logging:
|
|
driver: "json-file"
|
|
options:
|
|
max-size: "10m"
|
|
max-file: "3"
|
|
|
|
# ----------------------------------------------------
|
|
# 3. 游戏服务器 (Nakama)
|
|
# ----------------------------------------------------
|
|
nakama:
|
|
image: zfc931912343/bindbox-saolei:v1.6
|
|
container_name: nakama-server
|
|
environment:
|
|
- MINESWEEPER_BACKEND_URL=http://bindbox-game:9991/api/internal
|
|
- TZ=Asia/Shanghai
|
|
entrypoint:
|
|
- "/bin/sh"
|
|
- "-ecx"
|
|
- "/nakama/nakama migrate up --database.address root@nakama-db:26257 && exec /nakama/nakama --name nakama1 --database.address root@nakama-db:26257 --logger.level DEBUG --session.token_expiry_sec 7200 --metrics.prometheus_port 9100 --runtime.path /nakama/modules --matchmaker.interval_sec 1 --matchmaker.max_intervals 5"
|
|
restart: always
|
|
depends_on:
|
|
nakama-db:
|
|
condition: service_healthy
|
|
bindbox-game:
|
|
condition: service_started
|
|
volumes:
|
|
- nakama-data:/nakama/data
|
|
healthcheck:
|
|
test: [ "CMD", "wget", "--no-verbose", "--tries=1", "--spider", "http://bindbox-game:9991/" ]
|
|
interval: 10s
|
|
timeout: 5s
|
|
retries: 5
|
|
networks:
|
|
- bindbox_net
|
|
logging:
|
|
driver: "json-file"
|
|
options:
|
|
max-size: "10m"
|
|
max-file: "3"
|
|
|
|
# ----------------------------------------------------
|
|
# 4. MySQL Database
|
|
# ----------------------------------------------------
|
|
mysql:
|
|
image: mysql:8.0
|
|
container_name: bindbox-mysql
|
|
restart: always
|
|
ports:
|
|
- "3306:3306" # 临时开放外部访问,用完记得关闭!
|
|
environment:
|
|
MYSQL_ROOT_PASSWORD: "bindbox2025kdy"
|
|
MYSQL_DATABASE: "bindbox_game"
|
|
TZ: Asia/Shanghai
|
|
command: --default-authentication-plugin=mysql_native_password
|
|
volumes:
|
|
- mysql_data:/var/lib/mysql
|
|
- ./mysql/init:/docker-entrypoint-initdb.d # 初始化脚本
|
|
networks:
|
|
- bindbox_net
|
|
logging:
|
|
driver: "json-file"
|
|
options:
|
|
max-size: "10m"
|
|
max-file: "3"
|
|
|
|
# ----------------------------------------------------
|
|
# 5. Redis
|
|
# ----------------------------------------------------
|
|
redis:
|
|
image: redis:7.0
|
|
container_name: bindbox-redis
|
|
restart: always
|
|
volumes:
|
|
- redis_data:/data
|
|
networks:
|
|
- bindbox_net
|
|
logging:
|
|
driver: "json-file"
|
|
options:
|
|
max-size: "10m"
|
|
max-file: "3"
|
|
|
|
# ----------------------------------------------------
|
|
# 6. Nginx Gateway (入口)
|
|
# ----------------------------------------------------
|
|
nginx:
|
|
image: nginx:latest
|
|
container_name: bindbox-nginx
|
|
restart: always
|
|
ports:
|
|
- "80:80"
|
|
- "443:443"
|
|
volumes:
|
|
- ./nginx/conf.d:/etc/nginx/conf.d
|
|
- ./nginx/ssl:/etc/nginx/ssl
|
|
- ./nginx/admin:/usr/share/nginx/html/admin
|
|
- ./nginx/game:/usr/share/nginx/html/game
|
|
depends_on:
|
|
- bindbox-game
|
|
- nakama
|
|
networks:
|
|
- bindbox_net
|
|
logging:
|
|
driver: "json-file"
|
|
options:
|
|
max-size: "10m"
|
|
max-file: "3"
|
|
|
|
# ----------------------------------------------------
|
|
# 7. Loki (日志存储)
|
|
# ----------------------------------------------------
|
|
loki:
|
|
image: grafana/loki:3.0.0
|
|
container_name: bindbox-loki
|
|
restart: always
|
|
volumes:
|
|
# 必须上传 loki 目录到服务器
|
|
- ./loki/loki-config.yaml:/etc/loki/local-config.yaml
|
|
- loki_data:/loki
|
|
command: -config.file=/etc/loki/local-config.yaml
|
|
networks:
|
|
- bindbox_net
|
|
logging:
|
|
driver: "json-file"
|
|
options:
|
|
max-size: "10m"
|
|
max-file: "3"
|
|
|
|
# ----------------------------------------------------
|
|
# 8. Promtail (日志采集)
|
|
# ----------------------------------------------------
|
|
promtail:
|
|
image: grafana/promtail:3.0.0
|
|
container_name: bindbox-promtail
|
|
restart: always
|
|
volumes:
|
|
- ./loki/promtail-config.yaml:/etc/promtail/config.yaml
|
|
- /var/lib/docker/containers:/var/lib/docker/containers:ro
|
|
- /var/run/docker.sock:/var/run/docker.sock
|
|
# 采集当前目录下的 logs 文件夹
|
|
- ./logs:/var/log/bindbox-game:ro
|
|
command: -config.file=/etc/promtail/config.yaml
|
|
networks:
|
|
- bindbox_net
|
|
depends_on:
|
|
- loki
|
|
logging:
|
|
driver: "json-file"
|
|
options:
|
|
max-size: "10m"
|
|
max-file: "3"
|
|
|
|
# ----------------------------------------------------
|
|
# 9. Grafana (日志界面)
|
|
# ----------------------------------------------------
|
|
grafana:
|
|
image: grafana/grafana:latest
|
|
container_name: bindbox-grafana
|
|
restart: always
|
|
ports:
|
|
- "3000:3000"
|
|
environment:
|
|
- GF_SECURITY_ADMIN_PASSWORD=admin
|
|
- GF_USERS_ALLOW_SIGN_UP=false
|
|
volumes:
|
|
- grafana_data:/var/lib/grafana
|
|
networks:
|
|
- bindbox_net
|
|
depends_on:
|
|
- loki
|
|
logging:
|
|
driver: "json-file"
|
|
options:
|
|
max-size: "10m"
|
|
max-file: "3"
|
|
|
|
# ----------------------------------------------------
|
|
# 10. Prometheus (指标采集)
|
|
# ----------------------------------------------------
|
|
prometheus:
|
|
image: prom/prometheus:latest
|
|
container_name: bindbox-prometheus
|
|
restart: always
|
|
volumes:
|
|
- ./prometheus/prometheus.yml:/etc/prometheus/prometheus.yml
|
|
- prometheus_data:/prometheus
|
|
command:
|
|
- '--config.file=/etc/prometheus/prometheus.yml'
|
|
- '--storage.tsdb.path=/prometheus'
|
|
- '--web.enable-lifecycle'
|
|
networks:
|
|
- bindbox_net
|
|
logging:
|
|
driver: "json-file"
|
|
options:
|
|
max-size: "10m"
|
|
max-file: "3"
|
|
|
|
# ----------------------------------------------------
|
|
# 11. Nginx Exporter (Nginx指标导出)
|
|
# ----------------------------------------------------
|
|
nginx-exporter:
|
|
image: nginx/nginx-prometheus-exporter:latest
|
|
container_name: bindbox-nginx-exporter
|
|
restart: always
|
|
command:
|
|
- -nginx.scrape-uri=http://nginx:80/nginx_status
|
|
networks:
|
|
- bindbox_net
|
|
depends_on:
|
|
- nginx
|
|
logging:
|
|
driver: "json-file"
|
|
options:
|
|
max-size: "10m"
|
|
max-file: "3"
|
|
|
|
# ----------------------------------------------------
|
|
# 12. Redis Exporter (Redis指标导出)
|
|
# ----------------------------------------------------
|
|
redis-exporter:
|
|
image: oliver006/redis_exporter:latest
|
|
container_name: bindbox-redis-exporter
|
|
restart: always
|
|
environment:
|
|
- REDIS_ADDR=redis://redis:6379
|
|
networks:
|
|
- bindbox_net
|
|
depends_on:
|
|
- redis
|
|
logging:
|
|
driver: "json-file"
|
|
options:
|
|
max-size: "10m"
|
|
max-file: "3"
|
|
|
|
# ----------------------------------------------------
|
|
# 13. MySQL Exporter (MySQL指标导出)
|
|
# ----------------------------------------------------
|
|
mysql-exporter:
|
|
image: prom/mysqld-exporter:latest
|
|
container_name: bindbox-mysql-exporter
|
|
restart: always
|
|
command:
|
|
- --config.my-cnf=/etc/.my.cnf
|
|
volumes:
|
|
- ./mysql/.my.cnf:/etc/.my.cnf:ro
|
|
networks:
|
|
- bindbox_net
|
|
depends_on:
|
|
- mysql
|
|
logging:
|
|
driver: "json-file"
|
|
options:
|
|
max-size: "10m"
|
|
max-file: "3"
|
|
|
|
# ----------------------------------------------------
|
|
# 14. Tempo (链路追踪)
|
|
# ----------------------------------------------------
|
|
tempo:
|
|
image: grafana/tempo:latest
|
|
container_name: bindbox-tempo
|
|
restart: always
|
|
command: [ "-config.file=/etc/tempo/tempo-config.yaml" ]
|
|
volumes:
|
|
- ./tempo/tempo-config.yaml:/etc/tempo/tempo-config.yaml
|
|
- tempo_data:/var/tempo
|
|
networks:
|
|
- bindbox_net
|
|
logging:
|
|
driver: "json-file"
|
|
options:
|
|
max-size: "10m"
|
|
max-file: "3"
|
|
|
|
volumes:
|
|
nakama-db-data:
|
|
nakama-data:
|
|
mysql_data:
|
|
redis_data:
|
|
loki_data:
|
|
grafana_data:
|
|
prometheus_data:
|
|
tempo_data:
|
|
|
|
|
|
networks:
|
|
bindbox_net:
|
|
name: bindbox_net
|
|
driver: bridge
|