diff --git a/.env.example b/.env.example index 5e3a539..7553302 100644 --- a/.env.example +++ b/.env.example @@ -12,6 +12,11 @@ EZ_LOG_RETENTION_DAYS=30 EZ_LOG_MAX_RECORDS=1000000 EZ_LOG_PARTITIONING=off +# Log DB (docker-compose log-postgres) +LOG_POSTGRES_USER=postgres +LOG_POSTGRES_PASSWORD=postgres +LOG_POSTGRES_DB=ezapi_logs + # Data Plane EZ_BALANCER_PORT=8081 EZ_BALANCER_LOG_SINK_ENABLED=false diff --git a/README.md b/README.md index 13bcb54..143d403 100644 --- a/README.md +++ b/README.md @@ -111,7 +111,7 @@ go run cmd/server/main.go ### Docker Compose(推荐) -在 `ez-api` 目录使用自带的 `docker-compose.yml` 拉起完整栈(Postgres + Redis + ez-api + balancer): +在 `ez-api` 目录使用自带的 `docker-compose.yml` 拉起完整栈(Postgres + 日志库 + Redis + ez-api + balancer): ```bash cd ez-api @@ -123,6 +123,9 @@ docker compose up -d ```env EZ_ADMIN_TOKEN=admin123 EZ_INTERNAL_STATS_TOKEN=internal123 +LOG_POSTGRES_USER=postgres +LOG_POSTGRES_PASSWORD=postgres +LOG_POSTGRES_DB=ezapi_logs EZ_BALANCER_LOG_SINK_ENABLED=false EZ_BALANCER_LOG_SINK_BASE_URL=http://ez-api:8080 EZ_BALANCER_STATS_FLUSH_ENABLED=false diff --git a/docker-compose.yml b/docker-compose.yml index ab05349..9ae0e61 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -21,6 +21,26 @@ services: networks: - ez-network + # 1.1 Log PostgreSQL Database + log-postgres: + image: postgres:15-alpine + container_name: ez-log-postgres + environment: + POSTGRES_USER: ${LOG_POSTGRES_USER:-postgres} + POSTGRES_PASSWORD: ${LOG_POSTGRES_PASSWORD:-postgres} + POSTGRES_DB: ${LOG_POSTGRES_DB:-ezapi_logs} + ports: + - "5435:5432" + volumes: + - log_postgres_data:/var/lib/postgresql/data + healthcheck: + test: ["CMD-SHELL", "pg_isready -U postgres"] + interval: 5s + timeout: 5s + retries: 5 + networks: + - ez-network + # 2. Redis Cache redis: image: redis:7-alpine @@ -49,7 +69,7 @@ services: environment: EZ_API_PORT: ${EZ_API_PORT:-8080} EZ_PG_DSN: ${EZ_PG_DSN:-host=postgres user=postgres password=postgres dbname=ezapi port=5432 sslmode=disable} - EZ_LOG_PG_DSN: ${EZ_LOG_PG_DSN:-} + EZ_LOG_PG_DSN: ${EZ_LOG_PG_DSN:-host=log-postgres user=postgres password=postgres dbname=ezapi_logs port=5432 sslmode=disable} EZ_REDIS_ADDR: ${EZ_REDIS_ADDR:-redis:6379} EZ_REDIS_PASSWORD: ${EZ_REDIS_PASSWORD} EZ_REDIS_DB: ${EZ_REDIS_DB:-0} @@ -62,6 +82,8 @@ services: depends_on: postgres: condition: service_healthy + log-postgres: + condition: service_healthy redis: condition: service_healthy networks: @@ -97,6 +119,7 @@ services: volumes: postgres_data: + log_postgres_data: redis_data: networks: