From 611a26a59a0b734e08d632ec4faf8ca85e56f8c0 Mon Sep 17 00:00:00 2001 From: fanfpy Date: Sun, 6 Jul 2025 16:19:32 +0800 Subject: [PATCH] =?UTF-8?q?refactor(config):=20=E9=87=8D=E6=9E=84=E9=85=8D?= =?UTF-8?q?=E7=BD=AE=E6=96=87=E4=BB=B6=E7=BB=93=E6=9E=84=E4=B8=BA=E7=8E=AF?= =?UTF-8?q?=E5=A2=83=E5=88=86=E7=A6=BB=E6=A8=A1=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 将consul和traefik的配置文件按dev和prod环境分离 删除旧的单一配置文件,新增环境特定配置 更新docker-compose.yml以支持环境配置切换 --- consul/config/{ => dev}/consul.json | 0 consul/config/{ => dev}/data-service.json | 0 consul/config/{ => dev}/emotion-service.json | 0 consul/config/{ => dev}/frontend.json | 0 consul/config/{ => dev}/quant-service.json | 0 .../config/{ => dev}/recommend-service.json | 0 consul/config/{ => dev}/user-service.json | 0 consul/config/{ => dev}/whoami.json | 0 consul/config/prod/consul.json | 9 ++++++++ consul/config/prod/data-service.json | 18 ++++++++++++++++ consul/config/prod/emotion-service.json | 18 ++++++++++++++++ consul/config/prod/frontend.json | 18 ++++++++++++++++ consul/config/prod/quant-service.json | 18 ++++++++++++++++ consul/config/prod/recommend-service.json | 18 ++++++++++++++++ consul/config/prod/user-service.json | 18 ++++++++++++++++ consul/config/prod/whoami.json | 20 ++++++++++++++++++ docker-compose.yml | 8 +++---- traefik/{ => config/dev}/traefik.yml | 0 traefik/config/prod/traefik.yml | 21 +++++++++++++++++++ 19 files changed, 162 insertions(+), 4 deletions(-) rename consul/config/{ => dev}/consul.json (100%) rename consul/config/{ => dev}/data-service.json (100%) rename consul/config/{ => dev}/emotion-service.json (100%) rename consul/config/{ => dev}/frontend.json (100%) rename consul/config/{ => dev}/quant-service.json (100%) rename consul/config/{ => dev}/recommend-service.json (100%) rename consul/config/{ => dev}/user-service.json (100%) rename consul/config/{ => dev}/whoami.json (100%) create mode 100644 consul/config/prod/consul.json create mode 100644 consul/config/prod/data-service.json create mode 100644 consul/config/prod/emotion-service.json create mode 100644 consul/config/prod/frontend.json create mode 100644 consul/config/prod/quant-service.json create mode 100644 consul/config/prod/recommend-service.json create mode 100644 consul/config/prod/user-service.json create mode 100644 consul/config/prod/whoami.json rename traefik/{ => config/dev}/traefik.yml (100%) create mode 100644 traefik/config/prod/traefik.yml diff --git a/consul/config/consul.json b/consul/config/dev/consul.json similarity index 100% rename from consul/config/consul.json rename to consul/config/dev/consul.json diff --git a/consul/config/data-service.json b/consul/config/dev/data-service.json similarity index 100% rename from consul/config/data-service.json rename to consul/config/dev/data-service.json diff --git a/consul/config/emotion-service.json b/consul/config/dev/emotion-service.json similarity index 100% rename from consul/config/emotion-service.json rename to consul/config/dev/emotion-service.json diff --git a/consul/config/frontend.json b/consul/config/dev/frontend.json similarity index 100% rename from consul/config/frontend.json rename to consul/config/dev/frontend.json diff --git a/consul/config/quant-service.json b/consul/config/dev/quant-service.json similarity index 100% rename from consul/config/quant-service.json rename to consul/config/dev/quant-service.json diff --git a/consul/config/recommend-service.json b/consul/config/dev/recommend-service.json similarity index 100% rename from consul/config/recommend-service.json rename to consul/config/dev/recommend-service.json diff --git a/consul/config/user-service.json b/consul/config/dev/user-service.json similarity index 100% rename from consul/config/user-service.json rename to consul/config/dev/user-service.json diff --git a/consul/config/whoami.json b/consul/config/dev/whoami.json similarity index 100% rename from consul/config/whoami.json rename to consul/config/dev/whoami.json diff --git a/consul/config/prod/consul.json b/consul/config/prod/consul.json new file mode 100644 index 0000000..0aa6a91 --- /dev/null +++ b/consul/config/prod/consul.json @@ -0,0 +1,9 @@ +{ + "acl": { + "default_policy": "deny", + "enabled": true + }, + "ui_config": { + "enabled": false + } +} \ No newline at end of file diff --git a/consul/config/prod/data-service.json b/consul/config/prod/data-service.json new file mode 100644 index 0000000..149ae67 --- /dev/null +++ b/consul/config/prod/data-service.json @@ -0,0 +1,18 @@ +{ + "service": { + "address": "data-service", + "check": { + "http": "http://ari-data-service:8000/api/public/stock_bid_ask_em?symbol=000001", + "interval": "10s", + "timeout": "5s" + }, + "id": "data-service-1", + "tags": [ + "traefik.enable=true", + "traefik.http.routers.data-service.rule=Host(\"data.aristockai.com\")", + "traefik.http.routers.data-service.entrypoints=web" + ], + "name": "data-service", + "port": 8000 + } +} \ No newline at end of file diff --git a/consul/config/prod/emotion-service.json b/consul/config/prod/emotion-service.json new file mode 100644 index 0000000..0919352 --- /dev/null +++ b/consul/config/prod/emotion-service.json @@ -0,0 +1,18 @@ +{ + "service": { + "address": "emotion-service", + "check": { + "http": "http://emotion-service:8002/health", + "interval": "10s", + "timeout": "5s" + }, + "id": "emotion-service-1", + "tags": [ + "traefik.enable=true", + "traefik.http.routers.emotion-service.rule=Host(\"emotion.aristockai.com\")", + "traefik.http.routers.emotion-service.entrypoints=web" + ], + "name": "emotion-service", + "port": 8002 + } +} \ No newline at end of file diff --git a/consul/config/prod/frontend.json b/consul/config/prod/frontend.json new file mode 100644 index 0000000..e191e41 --- /dev/null +++ b/consul/config/prod/frontend.json @@ -0,0 +1,18 @@ +{ + "service": { + "address": "frontend", + "check": { + "http": "http://frontend:80/", + "interval": "10s", + "timeout": "5s" + }, + "id": "frontend-1", + "tags": [ + "traefik.enable=true", + "traefik.http.routers.frontend.rule=Host(\"aristockai.com\") || Host(\"www.aristockai.com\")", + "traefik.http.routers.frontend.entrypoints=web" + ], + "name": "frontend", + "port": 80 + } +} \ No newline at end of file diff --git a/consul/config/prod/quant-service.json b/consul/config/prod/quant-service.json new file mode 100644 index 0000000..ef7a1ea --- /dev/null +++ b/consul/config/prod/quant-service.json @@ -0,0 +1,18 @@ +{ + "service": { + "address": "quant-service", + "check": { + "http": "http://quant-service:8001/health", + "interval": "10s", + "timeout": "5s" + }, + "id": "quant-service-1", + "tags": [ + "traefik.enable=true", + "traefik.http.routers.quant-service.rule=Host(\"quant.aristockai.com\")", + "traefik.http.routers.quant-service.entrypoints=web" + ], + "name": "quant-service", + "port": 8001 + } +} \ No newline at end of file diff --git a/consul/config/prod/recommend-service.json b/consul/config/prod/recommend-service.json new file mode 100644 index 0000000..61dfe90 --- /dev/null +++ b/consul/config/prod/recommend-service.json @@ -0,0 +1,18 @@ +{ + "service": { + "address": "recommend-service", + "check": { + "http": "http://recommend-service:8003/health", + "interval": "10s", + "timeout": "5s" + }, + "id": "recommend-service-1", + "tags": [ + "traefik.enable=true", + "traefik.http.routers.recommend-service.rule=Host(\"recommend.aristockai.com\")", + "traefik.http.routers.recommend-service.entrypoints=web" + ], + "name": "recommend-service", + "port": 8003 + } +} \ No newline at end of file diff --git a/consul/config/prod/user-service.json b/consul/config/prod/user-service.json new file mode 100644 index 0000000..0384d27 --- /dev/null +++ b/consul/config/prod/user-service.json @@ -0,0 +1,18 @@ +{ + "service": { + "address": "user-service", + "check": { + "http": "http://user-service:8004/health", + "interval": "10s", + "timeout": "5s" + }, + "id": "user-service-1", + "tags": [ + "traefik.enable=true", + "traefik.http.routers.user-service.rule=Host(\"user.aristockai.com\")", + "traefik.http.routers.user-service.entrypoints=web" + ], + "name": "user-service", + "port": 8004 + } +} \ No newline at end of file diff --git a/consul/config/prod/whoami.json b/consul/config/prod/whoami.json new file mode 100644 index 0000000..93eda8c --- /dev/null +++ b/consul/config/prod/whoami.json @@ -0,0 +1,20 @@ +{ + "service": { + "name": "whoami", + "tags": [ + "traefik.enable=true", + "traefik.http.routers.whoami.entrypoints=web", + "traefik.http.routers.whoami.rule=Path(\"/whoami\")", + "traefik.http.services.whoami.loadbalancer.server.port=80" + ], + "address": "whoami", + "port": 80, + "checks": [ + { + "http": "http://whoami:80/", + "interval": "10s", + "timeout": "2s" + } + ] + } +} diff --git a/docker-compose.yml b/docker-compose.yml index babba39..e074844 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -13,8 +13,8 @@ services: - "8500:8500" # Consul Web UI - "8600:8600/udp" # DNS服务 volumes: - - ./consul/config:/consul/config - command: "consul agent -dev -config-dir=/consul/config -client=0.0.0.0" + - ./consul/config/${ENV_CONFIG_DIR}:/consul/config + command: "consul agent ${CONSUL_DEV_MODE} -config-dir=/consul/config -client=0.0.0.0" networks: - microservice-network healthcheck: @@ -33,7 +33,7 @@ services: - "8080:8080" # Traefik dashboard volumes: - /var/run/docker.sock:/var/run/docker.sock - - ./traefik/traefik.yml:/etc/traefik/traefik.yml + - ./traefik/config/${TRAEFIK_CONFIG_DIR}/traefik.yml:/etc/traefik/traefik.yml networks: - microservice-network @@ -42,7 +42,7 @@ services: container_name: ari-data-service restart: always ports: - - "8000:8000" # 错误:应为服务端口注释而非Traefik dashboard + - "8000:8000" networks: - microservice-network environment: diff --git a/traefik/traefik.yml b/traefik/config/dev/traefik.yml similarity index 100% rename from traefik/traefik.yml rename to traefik/config/dev/traefik.yml diff --git a/traefik/config/prod/traefik.yml b/traefik/config/prod/traefik.yml new file mode 100644 index 0000000..e41a458 --- /dev/null +++ b/traefik/config/prod/traefik.yml @@ -0,0 +1,21 @@ +entryPoints: + web: + address: ":80" + http: + redirections: + entryPoint: + to: websecure + scheme: https + websecure: + address: ":443" + + +providers: + consulCatalog: + endpoint: + address: "ari-consul:8500" + exposedByDefault: false + +api: + dashboard: true + insecure: false \ No newline at end of file