From e8fac3b5365d8d2038f5ee0ebd184fa068ab27b5 Mon Sep 17 00:00:00 2001 From: fanfpy Date: Mon, 30 Jun 2025 17:06:54 +0800 Subject: [PATCH 01/23] =?UTF-8?q?refactor(consul):=20=E5=B0=86=E6=9C=8D?= =?UTF-8?q?=E5=8A=A1=E9=85=8D=E7=BD=AE=E4=BB=8Ehcl=E8=BF=81=E7=A7=BB?= =?UTF-8?q?=E8=87=B3json=E6=A0=BC=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 迁移所有Consul服务配置从HCL格式到JSON格式,以统一配置管理方式 更新traefik配置以支持Consul服务发现 添加whoami服务用于测试 --- consul/config/consul.hcl | 8 ------- consul/config/consul.json | 9 ++++++++ consul/config/data-service.hcl | 17 -------------- consul/config/data-service.json | 17 ++++++++++++++ consul/config/emotion-service.hcl | 17 -------------- consul/config/emotion-service.json | 17 ++++++++++++++ consul/config/frontend.hcl | 17 -------------- consul/config/frontend.json | 17 ++++++++++++++ consul/config/quant-service.hcl | 17 -------------- consul/config/quant-service.json | 17 ++++++++++++++ consul/config/recommend-service.hcl | 17 -------------- consul/config/recommend-service.json | 17 ++++++++++++++ consul/config/user-service.hcl | 17 -------------- consul/config/user-service.json | 17 ++++++++++++++ consul/config/whoami.json | 11 +++++++++ docker-compose.yml | 34 +++++++++------------------- traefik/traefik.yml | 14 ++++++++---- 17 files changed, 143 insertions(+), 137 deletions(-) delete mode 100644 consul/config/consul.hcl create mode 100644 consul/config/consul.json delete mode 100644 consul/config/data-service.hcl create mode 100644 consul/config/data-service.json delete mode 100644 consul/config/emotion-service.hcl create mode 100644 consul/config/emotion-service.json delete mode 100644 consul/config/frontend.hcl create mode 100644 consul/config/frontend.json delete mode 100644 consul/config/quant-service.hcl create mode 100644 consul/config/quant-service.json delete mode 100644 consul/config/recommend-service.hcl create mode 100644 consul/config/recommend-service.json delete mode 100644 consul/config/user-service.hcl create mode 100644 consul/config/user-service.json create mode 100644 consul/config/whoami.json diff --git a/consul/config/consul.hcl b/consul/config/consul.hcl deleted file mode 100644 index 144ebe0..0000000 --- a/consul/config/consul.hcl +++ /dev/null @@ -1,8 +0,0 @@ -ui_config { - enabled = true -} - -acl { - enabled = false - default_policy = "deny" -} \ No newline at end of file diff --git a/consul/config/consul.json b/consul/config/consul.json new file mode 100644 index 0000000..45575db --- /dev/null +++ b/consul/config/consul.json @@ -0,0 +1,9 @@ +{ + "acl": { + "default_policy": "deny", + "enabled": false + }, + "ui_config": { + "enabled": true + } +} \ No newline at end of file diff --git a/consul/config/data-service.hcl b/consul/config/data-service.hcl deleted file mode 100644 index a87bccb..0000000 --- a/consul/config/data-service.hcl +++ /dev/null @@ -1,17 +0,0 @@ -service { - name = "data-service" - id = "data-service-1" - address = "data-service" - port = 8000 - - check { - http = "http://aktools:8080/quote_zh_a_hist?symbol=sh600000&period=daily&start_date=20220101&end_date=20220102" - interval = "10s" - timeout = "5s" - } - - meta = { - traefik_enable = "true" - traefik_http_routers_data_service_rule = "PathPrefix(`/api/data`)" - } -} \ No newline at end of file diff --git a/consul/config/data-service.json b/consul/config/data-service.json new file mode 100644 index 0000000..24faf96 --- /dev/null +++ b/consul/config/data-service.json @@ -0,0 +1,17 @@ +{ + "service": { + "address": "data-service", + "check": { + "http": "http://aktools:8080/api/public/stock_bid_ask_em?symbol=000001", + "interval": "10s", + "timeout": "5s" + }, + "id": "data-service-1", + "meta": { + "traefik_enable": "true", + "traefik_http_routers_data_service_rule": "PathPrefix(`/api/data`)" + }, + "name": "data-service", + "port": 8000 + } +} \ No newline at end of file diff --git a/consul/config/emotion-service.hcl b/consul/config/emotion-service.hcl deleted file mode 100644 index bed3c45..0000000 --- a/consul/config/emotion-service.hcl +++ /dev/null @@ -1,17 +0,0 @@ -service { - name = "emotion-service" - id = "emotion-service-1" - address = "emotion-service" - port = 8002 - - check { - http = "http://emotion-service:8002/health" - interval = "10s" - timeout = "5s" - } - - meta = { - traefik_enable = "true" - traefik_http_routers_emotion_service_rule = "PathPrefix(`/api/emotion`)" - } -} \ No newline at end of file diff --git a/consul/config/emotion-service.json b/consul/config/emotion-service.json new file mode 100644 index 0000000..258d5c5 --- /dev/null +++ b/consul/config/emotion-service.json @@ -0,0 +1,17 @@ +{ + "service": { + "address": "emotion-service", + "check": { + "http": "http://emotion-service:8002/health", + "interval": "10s", + "timeout": "5s" + }, + "id": "emotion-service-1", + "meta": { + "traefik_enable": "true", + "traefik_http_routers_emotion_service_rule": "PathPrefix(`/api/emotion`)" + }, + "name": "emotion-service", + "port": 8002 + } +} \ No newline at end of file diff --git a/consul/config/frontend.hcl b/consul/config/frontend.hcl deleted file mode 100644 index 24dc2aa..0000000 --- a/consul/config/frontend.hcl +++ /dev/null @@ -1,17 +0,0 @@ -service { - name = "frontend" - id = "frontend-1" - address = "frontend" - port = 80 - - check { - http = "http://frontend:80/" - interval = "10s" - timeout = "5s" - } - - meta = { - traefik_enable = "true" - traefik_http_routers_frontend_rule = "PathPrefix(`/`)" - } -} \ No newline at end of file diff --git a/consul/config/frontend.json b/consul/config/frontend.json new file mode 100644 index 0000000..51d7769 --- /dev/null +++ b/consul/config/frontend.json @@ -0,0 +1,17 @@ +{ + "service": { + "address": "frontend", + "check": { + "http": "http://frontend:80/", + "interval": "10s", + "timeout": "5s" + }, + "id": "frontend-1", + "meta": { + "traefik_enable": "true", + "traefik_http_routers_frontend_rule": "PathPrefix(`/`)" + }, + "name": "frontend", + "port": 80 + } +} \ No newline at end of file diff --git a/consul/config/quant-service.hcl b/consul/config/quant-service.hcl deleted file mode 100644 index ae1434f..0000000 --- a/consul/config/quant-service.hcl +++ /dev/null @@ -1,17 +0,0 @@ -service { - name = "quant-service" - id = "quant-service-1" - address = "quant-service" - port = 8001 - - check { - http = "http://quant-service:8001/health" - interval = "10s" - timeout = "5s" - } - - meta = { - traefik_enable = "true" - traefik_http_routers_quant_service_rule = "PathPrefix(`/api/quant`)" - } -} \ No newline at end of file diff --git a/consul/config/quant-service.json b/consul/config/quant-service.json new file mode 100644 index 0000000..ed70c98 --- /dev/null +++ b/consul/config/quant-service.json @@ -0,0 +1,17 @@ +{ + "service": { + "address": "quant-service", + "check": { + "http": "http://quant-service:8001/health", + "interval": "10s", + "timeout": "5s" + }, + "id": "quant-service-1", + "meta": { + "traefik_enable": "true", + "traefik_http_routers_quant_service_rule": "PathPrefix(`/api/quant`)" + }, + "name": "quant-service", + "port": 8001 + } +} \ No newline at end of file diff --git a/consul/config/recommend-service.hcl b/consul/config/recommend-service.hcl deleted file mode 100644 index 8b31706..0000000 --- a/consul/config/recommend-service.hcl +++ /dev/null @@ -1,17 +0,0 @@ -service { - name = "recommend-service" - id = "recommend-service-1" - address = "recommend-service" - port = 8003 - - check { - http = "http://recommend-service:8003/health" - interval = "10s" - timeout = "5s" - } - - meta = { - traefik_enable = "true" - traefik_http_routers_recommend_service_rule = "PathPrefix(`/api/recommend`)" - } -} \ No newline at end of file diff --git a/consul/config/recommend-service.json b/consul/config/recommend-service.json new file mode 100644 index 0000000..897d1c9 --- /dev/null +++ b/consul/config/recommend-service.json @@ -0,0 +1,17 @@ +{ + "service": { + "address": "recommend-service", + "check": { + "http": "http://recommend-service:8003/health", + "interval": "10s", + "timeout": "5s" + }, + "id": "recommend-service-1", + "meta": { + "traefik_enable": "true", + "traefik_http_routers_recommend_service_rule": "PathPrefix(`/api/recommend`)" + }, + "name": "recommend-service", + "port": 8003 + } +} \ No newline at end of file diff --git a/consul/config/user-service.hcl b/consul/config/user-service.hcl deleted file mode 100644 index e498f3f..0000000 --- a/consul/config/user-service.hcl +++ /dev/null @@ -1,17 +0,0 @@ -service { - name = "user-service" - id = "user-service-1" - address = "user-service" - port = 8004 - - check { - http = "http://user-service:8004/health" - interval = "10s" - timeout = "5s" - } - - meta = { - traefik_enable = "true" - traefik_http_routers_user_service_rule = "PathPrefix(`/api/user`)" - } -} \ No newline at end of file diff --git a/consul/config/user-service.json b/consul/config/user-service.json new file mode 100644 index 0000000..0d96995 --- /dev/null +++ b/consul/config/user-service.json @@ -0,0 +1,17 @@ +{ + "service": { + "address": "user-service", + "check": { + "http": "http://user-service:8004/health", + "interval": "10s", + "timeout": "5s" + }, + "id": "user-service-1", + "meta": { + "traefik_enable": "true", + "traefik_http_routers_user_service_rule": "PathPrefix(`/api/user`)" + }, + "name": "user-service", + "port": 8004 + } +} \ No newline at end of file diff --git a/consul/config/whoami.json b/consul/config/whoami.json new file mode 100644 index 0000000..a4b24df --- /dev/null +++ b/consul/config/whoami.json @@ -0,0 +1,11 @@ +{ + "service": { + "name": "whoami", + "port": 80, + "tags": ["traefik.enable=true", "traefik.http.routers.whoami.rule=Host(`whoami.localhost`)", "traefik.http.routers.whoami.entrypoints=web"], + "check": { + "http": "http://whoami:80", + "interval": "10s" + } + } +} \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index 501f721..859da40 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -24,31 +24,14 @@ services: retries: 3 traefik: - image: traefik:v2.9 - container_name: ari-traefik - restart: always - depends_on: - consul: - condition: service_healthy + image: traefik:v2.11 + command: + - --configFile=/etc/traefik/traefik.yml ports: - - "80:80" # 主入口 - - "8080:8080" # Dashboard + - "80:80" + - "8080:8080" # Traefik dashboard volumes: - ./traefik/traefik.yml:/etc/traefik/traefik.yml - - /var/run/docker.sock:/var/run/docker.sock:ro - command: - - --providers.consulcatalog=true - - --providers.consulcatalog.endpoint.address=consul:8500 - - --providers.consulcatalog.exposedbydefault=false - - --api.dashboard=true - - --log.level=INFO - networks: - - microservice-network - labels: - - "traefik.enable=true" - - "traefik.http.routers.traefik-dashboard.rule=PathPrefix(`/dashboard`) || PathPrefix(`/api`)" - - "traefik.http.routers.traefik-dashboard.service=api@internal" - - "traefik.http.routers.traefik-dashboard.entrypoints=web" data-service: build: ./services/data-service @@ -135,4 +118,9 @@ services: networks: - microservice-network environment: - - SERVICE_NAME=frontend \ No newline at end of file + - SERVICE_NAME=frontend + + whoami: + image: traefik/whoami + expose: + - "80" # 可选,Traefik 可以自动发现,不暴露到宿主机 diff --git a/traefik/traefik.yml b/traefik/traefik.yml index ebeb765..83d5232 100644 --- a/traefik/traefik.yml +++ b/traefik/traefik.yml @@ -1,7 +1,13 @@ entryPoints: web: address: ":80" -http: - middlewares: - compress: - compress: true \ No newline at end of file + +providers: + consulCatalog: + endpoint: + address: "consul:8500" + exposedByDefault: false + +api: + dashboard: true + insecure: true \ No newline at end of file From caef72861940a7336a7523e464831e44a45b2a91 Mon Sep 17 00:00:00 2001 From: fanfpy Date: Mon, 30 Jun 2025 17:34:02 +0800 Subject: [PATCH 02/23] =?UTF-8?q?ci(traefik):=20=E6=B7=BB=E5=8A=A0docker?= =?UTF-8?q?=20provider=E9=85=8D=E7=BD=AE=E5=B9=B6=E6=8C=82=E8=BD=BDdocker.?= =?UTF-8?q?sock?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 在traefik配置中添加docker provider并设置exposedByDefault为false,同时在docker-compose中挂载docker.sock以支持容器发现 --- docker-compose.yml | 1 + traefik/traefik.yml | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/docker-compose.yml b/docker-compose.yml index 859da40..b8b41a0 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -31,6 +31,7 @@ services: - "80:80" - "8080:8080" # Traefik dashboard volumes: + - /var/run/docker.sock:/var/run/docker.sock - ./traefik/traefik.yml:/etc/traefik/traefik.yml data-service: diff --git a/traefik/traefik.yml b/traefik/traefik.yml index 83d5232..205a8ab 100644 --- a/traefik/traefik.yml +++ b/traefik/traefik.yml @@ -2,7 +2,11 @@ entryPoints: web: address: ":80" + providers: + docker: + exposedByDefault: false + consulCatalog: endpoint: address: "consul:8500" From 470d69d073c72cd384df82ac1e1da2e3743593c0 Mon Sep 17 00:00:00 2001 From: fanfpy Date: Mon, 30 Jun 2025 18:16:57 +0800 Subject: [PATCH 03/23] =?UTF-8?q?refactor(consul):=20=E6=9B=B4=E6=96=B0?= =?UTF-8?q?=E6=9C=8D=E5=8A=A1=E9=85=8D=E7=BD=AE=E5=92=8Cdocker-compose?= =?UTF-8?q?=E8=AE=BE=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 修改data-service的consul检查端口为8000 - 将whoami服务的traefik配置从tags迁移到meta - 简化docker-compose.yml,注释掉未使用的服务 --- consul/config/data-service.json | 2 +- consul/config/whoami.json | 6 +- docker-compose.yml | 145 +++++++++++++++----------------- 3 files changed, 76 insertions(+), 77 deletions(-) diff --git a/consul/config/data-service.json b/consul/config/data-service.json index 24faf96..9bdc3fc 100644 --- a/consul/config/data-service.json +++ b/consul/config/data-service.json @@ -2,7 +2,7 @@ "service": { "address": "data-service", "check": { - "http": "http://aktools:8080/api/public/stock_bid_ask_em?symbol=000001", + "http": "http://aktools:8000/api/public/stock_bid_ask_em?symbol=000001", "interval": "10s", "timeout": "5s" }, diff --git a/consul/config/whoami.json b/consul/config/whoami.json index a4b24df..ed690e5 100644 --- a/consul/config/whoami.json +++ b/consul/config/whoami.json @@ -2,7 +2,11 @@ "service": { "name": "whoami", "port": 80, - "tags": ["traefik.enable=true", "traefik.http.routers.whoami.rule=Host(`whoami.localhost`)", "traefik.http.routers.whoami.entrypoints=web"], + "meta": { + "traefik_enable": "true", + "traefik_http_routers_whoami_rule": "PathPrefix(`/whoami`)", + "traefik_http_routers_whoami_entrypoints": "web" + }, "check": { "http": "http://whoami:80", "interval": "10s" diff --git a/docker-compose.yml b/docker-compose.yml index b8b41a0..9fe88b4 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -38,90 +38,85 @@ services: build: ./services/data-service container_name: ari-data-service restart: always - depends_on: - consul: - condition: service_healthy - expose: - - "8000" + ports: + - "8000:8000" # Traefik dashboard networks: - microservice-network environment: - SERVICE_NAME=data-service - quant-service: - build: ./services/quant-service - container_name: ari-quant-service - restart: always - depends_on: - consul: - condition: service_healthy - expose: - - "8001" - networks: - - microservice-network - environment: - - SERVICE_NAME=quant-service + # quant-service: + # build: ./services/quant-service + # container_name: ari-quant-service + # restart: always + # depends_on: + # consul: + # condition: service_healthy + # expose: + # - "8001" + # networks: + # - microservice-network + # environment: + # - SERVICE_NAME=quant-service - emotion-service: - build: ./services/emotion-service - container_name: ari-emotion-service - restart: always - depends_on: - consul: - condition: service_healthy - expose: - - "8002" - networks: - - microservice-network - environment: - - SERVICE_NAME=emotion-service + # emotion-service: + # build: ./services/emotion-service + # container_name: ari-emotion-service + # restart: always + # depends_on: + # consul: + # condition: service_healthy + # expose: + # - "8002" + # networks: + # - microservice-network + # environment: + # - SERVICE_NAME=emotion-service - recommend-service: - build: ./services/recommend-service - container_name: ari-recommend-service - restart: always - depends_on: - consul: - condition: service_healthy - expose: - - "8003" - networks: - - microservice-network - environment: - - SERVICE_NAME=recommend-service + # recommend-service: + # build: ./services/recommend-service + # container_name: ari-recommend-service + # restart: always + # depends_on: + # consul: + # condition: service_healthy + # expose: + # - "8003" + # networks: + # - microservice-network + # environment: + # - SERVICE_NAME=recommend-service - user-service: - build: ./services/user-service - container_name: ari-user-service - restart: always - depends_on: - consul: - condition: service_healthy - expose: - - "8004" - networks: - - microservice-network - environment: - - SERVICE_NAME=user-service + # user-service: + # build: ./services/user-service + # container_name: ari-user-service + # restart: always + # depends_on: + # consul: + # condition: service_healthy + # expose: + # - "8004" + # networks: + # - microservice-network + # environment: + # - SERVICE_NAME=user-service - frontend: - build: ./services/frontend - container_name: ari-frontend - restart: always - depends_on: - - data-service - - quant-service - - emotion-service - - recommend-service - - user-service - expose: - - "80" - networks: - - microservice-network - environment: - - SERVICE_NAME=frontend + # frontend: + # build: ./services/frontend + # container_name: ari-frontend + # restart: always + # depends_on: + # - data-service + # - quant-service + # - emotion-service + # - recommend-service + # - user-service + # expose: + # - "80" + # networks: + # - microservice-network + # environment: + # - SERVICE_NAME=frontend whoami: image: traefik/whoami - expose: - - "80" # 可选,Traefik 可以自动发现,不暴露到宿主机 From 4d766d2f1d9db6723c57d8f5d50b8139759d2d9c Mon Sep 17 00:00:00 2001 From: fanfpy Date: Mon, 30 Jun 2025 18:36:22 +0800 Subject: [PATCH 04/23] =?UTF-8?q?fix:=20=E6=9B=B4=E6=96=B0=E6=9C=8D?= =?UTF-8?q?=E5=8A=A1=E6=A3=80=E6=9F=A5=E5=9C=B0=E5=9D=80=E5=B9=B6=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=E5=AE=B9=E5=99=A8=E5=90=8D=E7=A7=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 将consul检查地址从aktools改为ari-data-service以确保正确性 为whoami服务添加container_name配置 --- consul/config/data-service.json | 2 +- docker-compose.yml | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/consul/config/data-service.json b/consul/config/data-service.json index 9bdc3fc..6513892 100644 --- a/consul/config/data-service.json +++ b/consul/config/data-service.json @@ -2,7 +2,7 @@ "service": { "address": "data-service", "check": { - "http": "http://aktools:8000/api/public/stock_bid_ask_em?symbol=000001", + "http": "http://ari-data-service:8000/api/public/stock_bid_ask_em?symbol=000001", "interval": "10s", "timeout": "5s" }, diff --git a/docker-compose.yml b/docker-compose.yml index 9fe88b4..33f4f06 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -120,3 +120,4 @@ services: whoami: image: traefik/whoami + container_name: whoami From b2a89252b288946822349d641284bac43d9d36db Mon Sep 17 00:00:00 2001 From: fanfpy Date: Mon, 30 Jun 2025 18:49:50 +0800 Subject: [PATCH 05/23] =?UTF-8?q?ci(docker):=20=E4=B8=BAtraefik=E5=92=8Cwh?= =?UTF-8?q?oami=E6=9C=8D=E5=8A=A1=E6=B7=BB=E5=8A=A0=E7=BD=91=E7=BB=9C?= =?UTF-8?q?=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 为traefik服务添加容器名称并使其与whoami服务加入同一微服务网络,确保服务间通信 --- docker-compose.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/docker-compose.yml b/docker-compose.yml index 33f4f06..78e9b58 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -25,6 +25,7 @@ services: traefik: image: traefik:v2.11 + container_name: ari-traefik command: - --configFile=/etc/traefik/traefik.yml ports: @@ -33,6 +34,8 @@ services: volumes: - /var/run/docker.sock:/var/run/docker.sock - ./traefik/traefik.yml:/etc/traefik/traefik.yml + networks: + - microservice-network data-service: build: ./services/data-service @@ -121,3 +124,5 @@ services: whoami: image: traefik/whoami container_name: whoami + networks: + - microservice-network From 2feaff1aa94851904c899b1bbe41839559ff7e22 Mon Sep 17 00:00:00 2001 From: fanfpy Date: Mon, 30 Jun 2025 18:54:54 +0800 Subject: [PATCH 06/23] =?UTF-8?q?fix(traefik):=20=E5=B0=86consul=E5=9C=B0?= =?UTF-8?q?=E5=9D=80=E6=9B=B4=E6=96=B0=E4=B8=BAari-consul=E4=BB=A5?= =?UTF-8?q?=E5=8C=B9=E9=85=8D=E6=9C=8D=E5=8A=A1=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- traefik/traefik.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/traefik/traefik.yml b/traefik/traefik.yml index 205a8ab..684f462 100644 --- a/traefik/traefik.yml +++ b/traefik/traefik.yml @@ -9,7 +9,7 @@ providers: consulCatalog: endpoint: - address: "consul:8500" + address: "ari-consul:8500" exposedByDefault: false api: From 832c6c5a5962767901c639c52c8ae6835838b157 Mon Sep 17 00:00:00 2001 From: fanfpy Date: Tue, 1 Jul 2025 14:52:31 +0800 Subject: [PATCH 07/23] =?UTF-8?q?feat:=20=E5=90=AF=E7=94=A8docker=E6=9C=8D?= =?UTF-8?q?=E5=8A=A1=E8=87=AA=E5=8A=A8=E6=9A=B4=E9=9C=B2=E5=B9=B6=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=E5=A4=9A=E4=B8=AA=E5=BE=AE=E6=9C=8D=E5=8A=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 修改traefik配置以自动暴露docker服务 取消注释docker-compose中的quant-service等微服务 更新data-service的路由规则语法 --- consul/config/data-service.json | 2 +- docker-compose.yml | 136 ++++++++++++++++---------------- traefik/traefik.yml | 2 +- 3 files changed, 70 insertions(+), 70 deletions(-) diff --git a/consul/config/data-service.json b/consul/config/data-service.json index 6513892..437bd59 100644 --- a/consul/config/data-service.json +++ b/consul/config/data-service.json @@ -9,7 +9,7 @@ "id": "data-service-1", "meta": { "traefik_enable": "true", - "traefik_http_routers_data_service_rule": "PathPrefix(`/api/data`)" + "traefik_http_routers_data_service_rule": "PathPrefix('/api/data')" }, "name": "data-service", "port": 8000 diff --git a/docker-compose.yml b/docker-compose.yml index 78e9b58..f0d786d 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -48,78 +48,78 @@ services: environment: - SERVICE_NAME=data-service - # quant-service: - # build: ./services/quant-service - # container_name: ari-quant-service - # restart: always - # depends_on: - # consul: - # condition: service_healthy - # expose: - # - "8001" - # networks: - # - microservice-network - # environment: - # - SERVICE_NAME=quant-service + quant-service: + build: ./services/quant-service + container_name: ari-quant-service + restart: always + depends_on: + consul: + condition: service_healthy + expose: + - "8001" + networks: + - microservice-network + environment: + - SERVICE_NAME=quant-service - # emotion-service: - # build: ./services/emotion-service - # container_name: ari-emotion-service - # restart: always - # depends_on: - # consul: - # condition: service_healthy - # expose: - # - "8002" - # networks: - # - microservice-network - # environment: - # - SERVICE_NAME=emotion-service + emotion-service: + build: ./services/emotion-service + container_name: ari-emotion-service + restart: always + depends_on: + consul: + condition: service_healthy + expose: + - "8002" + networks: + - microservice-network + environment: + - SERVICE_NAME=emotion-service - # recommend-service: - # build: ./services/recommend-service - # container_name: ari-recommend-service - # restart: always - # depends_on: - # consul: - # condition: service_healthy - # expose: - # - "8003" - # networks: - # - microservice-network - # environment: - # - SERVICE_NAME=recommend-service + recommend-service: + build: ./services/recommend-service + container_name: ari-recommend-service + restart: always + depends_on: + consul: + condition: service_healthy + expose: + - "8003" + networks: + - microservice-network + environment: + - SERVICE_NAME=recommend-service - # user-service: - # build: ./services/user-service - # container_name: ari-user-service - # restart: always - # depends_on: - # consul: - # condition: service_healthy - # expose: - # - "8004" - # networks: - # - microservice-network - # environment: - # - SERVICE_NAME=user-service + user-service: + build: ./services/user-service + container_name: ari-user-service + restart: always + depends_on: + consul: + condition: service_healthy + expose: + - "8004" + networks: + - microservice-network + environment: + - SERVICE_NAME=user-service - # frontend: - # build: ./services/frontend - # container_name: ari-frontend - # restart: always - # depends_on: - # - data-service - # - quant-service - # - emotion-service - # - recommend-service - # - user-service - # expose: - # - "80" - # networks: - # - microservice-network - # environment: - # - SERVICE_NAME=frontend + frontend: + build: ./services/frontend + container_name: ari-frontend + restart: always + depends_on: + - data-service + - quant-service + - emotion-service + - recommend-service + - user-service + expose: + - "80" + networks: + - microservice-network + environment: + - SERVICE_NAME=frontend whoami: image: traefik/whoami diff --git a/traefik/traefik.yml b/traefik/traefik.yml index 684f462..5336a79 100644 --- a/traefik/traefik.yml +++ b/traefik/traefik.yml @@ -5,7 +5,7 @@ entryPoints: providers: docker: - exposedByDefault: false + exposedByDefault: true consulCatalog: endpoint: From e5808721587c9bc39c799bd72a204e1c6802d447 Mon Sep 17 00:00:00 2001 From: fanfpy Date: Tue, 1 Jul 2025 15:04:56 +0800 Subject: [PATCH 08/23] =?UTF-8?q?fix(traefik):=20=E6=9B=B4=E6=96=B0consulC?= =?UTF-8?q?atalog=E9=85=8D=E7=BD=AE=E5=B9=B6=E7=A7=BB=E9=99=A4docker?= =?UTF-8?q?=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 将consulCatalog的exposedByDefault设置为true以启用服务自动发现 移除不再使用的docker provider配置 --- traefik/traefik.yml | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/traefik/traefik.yml b/traefik/traefik.yml index 5336a79..84f204b 100644 --- a/traefik/traefik.yml +++ b/traefik/traefik.yml @@ -4,13 +4,10 @@ entryPoints: providers: - docker: - exposedByDefault: true - consulCatalog: endpoint: address: "ari-consul:8500" - exposedByDefault: false + exposedByDefault: true api: dashboard: true From f7cdfcbd1de5ec400b89806a3ac753a77ee5c5ab Mon Sep 17 00:00:00 2001 From: fanfpy Date: Tue, 1 Jul 2025 15:43:01 +0800 Subject: [PATCH 09/23] =?UTF-8?q?refactor(consul):=20=E7=BB=9F=E4=B8=80Tra?= =?UTF-8?q?efik=E8=B7=AF=E7=94=B1=E9=85=8D=E7=BD=AE=E6=A0=BC=E5=BC=8F?= =?UTF-8?q?=E5=B9=B6=E6=9B=B4=E6=96=B0whoami=E6=9C=8D=E5=8A=A1=E9=85=8D?= =?UTF-8?q?=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 将Traefik路由规则从下划线格式改为点分隔格式 - 更新whoami服务配置,使用tags替代meta并添加中间件配置 - 修复user-service和recommend-service中的拼写错误 --- consul/config/data-service.json | 2 +- consul/config/emotion-service.json | 2 +- consul/config/frontend.json | 2 +- consul/config/quant-service.json | 2 +- consul/config/recommend-service.json | 2 +- consul/config/user-service.json | 2 +- consul/config/whoami.json | 22 +++++++++++++++------- 7 files changed, 21 insertions(+), 13 deletions(-) diff --git a/consul/config/data-service.json b/consul/config/data-service.json index 437bd59..52ba919 100644 --- a/consul/config/data-service.json +++ b/consul/config/data-service.json @@ -9,7 +9,7 @@ "id": "data-service-1", "meta": { "traefik_enable": "true", - "traefik_http_routers_data_service_rule": "PathPrefix('/api/data')" + "traefik.http.routers.data-service.rule": "PathPrefix('/api/data')" }, "name": "data-service", "port": 8000 diff --git a/consul/config/emotion-service.json b/consul/config/emotion-service.json index 258d5c5..1818fb5 100644 --- a/consul/config/emotion-service.json +++ b/consul/config/emotion-service.json @@ -9,7 +9,7 @@ "id": "emotion-service-1", "meta": { "traefik_enable": "true", - "traefik_http_routers_emotion_service_rule": "PathPrefix(`/api/emotion`)" + "traefik.http.routers.emotion-service.rule": "PathPrefix('/api/emotion')" }, "name": "emotion-service", "port": 8002 diff --git a/consul/config/frontend.json b/consul/config/frontend.json index 51d7769..93efea8 100644 --- a/consul/config/frontend.json +++ b/consul/config/frontend.json @@ -9,7 +9,7 @@ "id": "frontend-1", "meta": { "traefik_enable": "true", - "traefik_http_routers_frontend_rule": "PathPrefix(`/`)" + "traefik.http.routers.frontend.rule": "PathPrefix('/')" }, "name": "frontend", "port": 80 diff --git a/consul/config/quant-service.json b/consul/config/quant-service.json index ed70c98..fe78f67 100644 --- a/consul/config/quant-service.json +++ b/consul/config/quant-service.json @@ -9,7 +9,7 @@ "id": "quant-service-1", "meta": { "traefik_enable": "true", - "traefik_http_routers_quant_service_rule": "PathPrefix(`/api/quant`)" + "traefik.http.routers.quant-service.rule": "PathPrefix('/api/quant')" }, "name": "quant-service", "port": 8001 diff --git a/consul/config/recommend-service.json b/consul/config/recommend-service.json index 897d1c9..923320d 100644 --- a/consul/config/recommend-service.json +++ b/consul/config/recommend-service.json @@ -9,7 +9,7 @@ "id": "recommend-service-1", "meta": { "traefik_enable": "true", - "traefik_http_routers_recommend_service_rule": "PathPrefix(`/api/recommend`)" + "raefik.http.routers.quant-service.rule": "PathPrefix(`/api/recommend`)" }, "name": "recommend-service", "port": 8003 diff --git a/consul/config/user-service.json b/consul/config/user-service.json index 0d96995..00cbcc3 100644 --- a/consul/config/user-service.json +++ b/consul/config/user-service.json @@ -9,7 +9,7 @@ "id": "user-service-1", "meta": { "traefik_enable": "true", - "traefik_http_routers_user_service_rule": "PathPrefix(`/api/user`)" + "raefik.http.routers.quant-service.rule": "PathPrefix(`/api/user`)" }, "name": "user-service", "port": 8004 diff --git a/consul/config/whoami.json b/consul/config/whoami.json index ed690e5..2fb6d29 100644 --- a/consul/config/whoami.json +++ b/consul/config/whoami.json @@ -1,15 +1,23 @@ { "service": { "name": "whoami", + "address": "whoami", "port": 80, - "meta": { - "traefik_enable": "true", - "traefik_http_routers_whoami_rule": "PathPrefix(`/whoami`)", - "traefik_http_routers_whoami_entrypoints": "web" - }, + "tags": [ + "traefik.enable=true", + "traefik.http.routers.whoami.rule=Host(`whoami.localhost`)", + "traefik.http.routers.whoami.entrypoints=web", + "traefik.http.routers.whoami.middlewares=whoami-prefix" + ], "check": { - "http": "http://whoami:80", + "http": "http://whoami:80/", "interval": "10s" } + }, + "middleware": { + "name": "whoami-prefix", + "pathPrefixStrip": { + "prefixes": ["/whoami"] + } } -} \ No newline at end of file +} From da3f8455916f7063f0b09225c28e2d03e3875882 Mon Sep 17 00:00:00 2001 From: fanfpy Date: Tue, 1 Jul 2025 16:38:55 +0800 Subject: [PATCH 10/23] =?UTF-8?q?refactor(consul):=20=E7=BB=9F=E4=B8=80Tra?= =?UTF-8?q?efik=E8=B7=AF=E7=94=B1=E8=A7=84=E5=88=99=E6=A0=BC=E5=BC=8F?= =?UTF-8?q?=E5=B9=B6=E7=AE=80=E5=8C=96whoami=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 将所有服务的Traefik路由规则从点分隔符改为下划线格式 - 简化whoami服务配置,移除中间件并更新路由规则 - 统一所有服务的配置格式以提高可维护性 --- consul/config/data-service.json | 2 +- consul/config/emotion-service.json | 2 +- consul/config/frontend.json | 2 +- consul/config/quant-service.json | 2 +- consul/config/recommend-service.json | 2 +- consul/config/user-service.json | 2 +- consul/config/whoami.json | 25 +++++++++++-------------- 7 files changed, 17 insertions(+), 20 deletions(-) diff --git a/consul/config/data-service.json b/consul/config/data-service.json index 52ba919..437bd59 100644 --- a/consul/config/data-service.json +++ b/consul/config/data-service.json @@ -9,7 +9,7 @@ "id": "data-service-1", "meta": { "traefik_enable": "true", - "traefik.http.routers.data-service.rule": "PathPrefix('/api/data')" + "traefik_http_routers_data_service_rule": "PathPrefix('/api/data')" }, "name": "data-service", "port": 8000 diff --git a/consul/config/emotion-service.json b/consul/config/emotion-service.json index 1818fb5..5d91c51 100644 --- a/consul/config/emotion-service.json +++ b/consul/config/emotion-service.json @@ -9,7 +9,7 @@ "id": "emotion-service-1", "meta": { "traefik_enable": "true", - "traefik.http.routers.emotion-service.rule": "PathPrefix('/api/emotion')" + "traefik_http_routers_emotion_service_rule": "PathPrefix('/api/emotion')" }, "name": "emotion-service", "port": 8002 diff --git a/consul/config/frontend.json b/consul/config/frontend.json index 93efea8..a2df057 100644 --- a/consul/config/frontend.json +++ b/consul/config/frontend.json @@ -9,7 +9,7 @@ "id": "frontend-1", "meta": { "traefik_enable": "true", - "traefik.http.routers.frontend.rule": "PathPrefix('/')" + "traefik_http_routers_frontend_rule": "PathPrefix('/')" }, "name": "frontend", "port": 80 diff --git a/consul/config/quant-service.json b/consul/config/quant-service.json index fe78f67..88b2e83 100644 --- a/consul/config/quant-service.json +++ b/consul/config/quant-service.json @@ -9,7 +9,7 @@ "id": "quant-service-1", "meta": { "traefik_enable": "true", - "traefik.http.routers.quant-service.rule": "PathPrefix('/api/quant')" + "traefik_http_routers_quant_service_rule": "PathPrefix('/api/quant')" }, "name": "quant-service", "port": 8001 diff --git a/consul/config/recommend-service.json b/consul/config/recommend-service.json index 923320d..9818eda 100644 --- a/consul/config/recommend-service.json +++ b/consul/config/recommend-service.json @@ -9,7 +9,7 @@ "id": "recommend-service-1", "meta": { "traefik_enable": "true", - "raefik.http.routers.quant-service.rule": "PathPrefix(`/api/recommend`)" + "traefik_http_routers_recommend_service_rule": "PathPrefix('/api/recommend')" }, "name": "recommend-service", "port": 8003 diff --git a/consul/config/user-service.json b/consul/config/user-service.json index 00cbcc3..a94219e 100644 --- a/consul/config/user-service.json +++ b/consul/config/user-service.json @@ -9,7 +9,7 @@ "id": "user-service-1", "meta": { "traefik_enable": "true", - "raefik.http.routers.quant-service.rule": "PathPrefix(`/api/user`)" + "traefik_http_routers_user_service_rule": "PathPrefix('/api/user')" }, "name": "user-service", "port": 8004 diff --git a/consul/config/whoami.json b/consul/config/whoami.json index 2fb6d29..6d47134 100644 --- a/consul/config/whoami.json +++ b/consul/config/whoami.json @@ -1,23 +1,20 @@ { "service": { "name": "whoami", - "address": "whoami", - "port": 80, "tags": [ "traefik.enable=true", - "traefik.http.routers.whoami.rule=Host(`whoami.localhost`)", "traefik.http.routers.whoami.entrypoints=web", - "traefik.http.routers.whoami.middlewares=whoami-prefix" + "traefik.http.routers.whoami.rule=Path(`/whoami`)", + "traefik.http.services.whoami.loadbalancer.server.port=80" ], - "check": { - "http": "http://whoami:80/", - "interval": "10s" - } - }, - "middleware": { - "name": "whoami-prefix", - "pathPrefixStrip": { - "prefixes": ["/whoami"] - } + "address": "whoami", + "port": 80, + "checks": [ + { + "http": "http://whoami:80/", + "interval": "10s", + "timeout": "2s" + } + ] } } From 302fbbc11bae972e74475126f192771d1a76b77c Mon Sep 17 00:00:00 2001 From: fanfpy Date: Tue, 1 Jul 2025 17:00:31 +0800 Subject: [PATCH 11/23] =?UTF-8?q?refactor(consul):=20=E5=B0=86=E6=9C=8D?= =?UTF-8?q?=E5=8A=A1=E9=85=8D=E7=BD=AE=E4=B8=AD=E7=9A=84meta=E5=AD=97?= =?UTF-8?q?=E6=AE=B5=E8=BF=81=E7=A7=BB=E4=B8=BAtags=E6=A0=BC=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 统一将Consul服务配置中的traefik相关元数据从meta字段迁移到tags数组格式 新增entrypoints配置以明确指定web入口点 --- consul/config/data-service.json | 9 +++++---- consul/config/emotion-service.json | 9 +++++---- consul/config/frontend.json | 9 +++++---- consul/config/quant-service.json | 9 +++++---- consul/config/recommend-service.json | 9 +++++---- consul/config/user-service.json | 9 +++++---- 6 files changed, 30 insertions(+), 24 deletions(-) diff --git a/consul/config/data-service.json b/consul/config/data-service.json index 437bd59..a70e02d 100644 --- a/consul/config/data-service.json +++ b/consul/config/data-service.json @@ -7,10 +7,11 @@ "timeout": "5s" }, "id": "data-service-1", - "meta": { - "traefik_enable": "true", - "traefik_http_routers_data_service_rule": "PathPrefix('/api/data')" - }, + "tags": [ + "traefik.enable=true", + "traefik.http.routers.data-service.rule=PathPrefix('/api/data')", + "traefik.http.routers.data-service.entrypoints=web" + ], "name": "data-service", "port": 8000 } diff --git a/consul/config/emotion-service.json b/consul/config/emotion-service.json index 5d91c51..fa6e12a 100644 --- a/consul/config/emotion-service.json +++ b/consul/config/emotion-service.json @@ -7,10 +7,11 @@ "timeout": "5s" }, "id": "emotion-service-1", - "meta": { - "traefik_enable": "true", - "traefik_http_routers_emotion_service_rule": "PathPrefix('/api/emotion')" - }, + "tags": [ + "traefik.enable=true", + "traefik.http.routers.emotion-service.rule=PathPrefix('/api/emotion')", + "traefik.http.routers.emotion-service.entrypoints=web" + ], "name": "emotion-service", "port": 8002 } diff --git a/consul/config/frontend.json b/consul/config/frontend.json index a2df057..50825fb 100644 --- a/consul/config/frontend.json +++ b/consul/config/frontend.json @@ -7,10 +7,11 @@ "timeout": "5s" }, "id": "frontend-1", - "meta": { - "traefik_enable": "true", - "traefik_http_routers_frontend_rule": "PathPrefix('/')" - }, + "tags": [ + "traefik.enable=true", + "traefik.http.routers.frontend.rule=PathPrefix('/')", + "traefik.http.routers.frontend.entrypoints=web" + ], "name": "frontend", "port": 80 } diff --git a/consul/config/quant-service.json b/consul/config/quant-service.json index 88b2e83..faff493 100644 --- a/consul/config/quant-service.json +++ b/consul/config/quant-service.json @@ -7,10 +7,11 @@ "timeout": "5s" }, "id": "quant-service-1", - "meta": { - "traefik_enable": "true", - "traefik_http_routers_quant_service_rule": "PathPrefix('/api/quant')" - }, + "tags": [ + "traefik.enable=true", + "traefik.http.routers.quant-service.rule=PathPrefix('/api/quant')", + "traefik.http.routers.quant-service.entrypoints=web" + ], "name": "quant-service", "port": 8001 } diff --git a/consul/config/recommend-service.json b/consul/config/recommend-service.json index 9818eda..b277a6f 100644 --- a/consul/config/recommend-service.json +++ b/consul/config/recommend-service.json @@ -7,10 +7,11 @@ "timeout": "5s" }, "id": "recommend-service-1", - "meta": { - "traefik_enable": "true", - "traefik_http_routers_recommend_service_rule": "PathPrefix('/api/recommend')" - }, + "tags": [ + "traefik.enable=true", + "traefik.http.routers.recommend-service.rule=PathPrefix('/api/recommend')", + "traefik.http.routers.recommend-service.entrypoints=web" + ], "name": "recommend-service", "port": 8003 } diff --git a/consul/config/user-service.json b/consul/config/user-service.json index a94219e..37c25a8 100644 --- a/consul/config/user-service.json +++ b/consul/config/user-service.json @@ -7,10 +7,11 @@ "timeout": "5s" }, "id": "user-service-1", - "meta": { - "traefik_enable": "true", - "traefik_http_routers_user_service_rule": "PathPrefix('/api/user')" - }, + "tags": [ + "traefik.enable=true", + "traefik.http.routers.user-service.rule=PathPrefix('/api/user')", + "traefik.http.routers.user-service.entrypoints=web" + ], "name": "user-service", "port": 8004 } From 2ba55b4daedd7fdc767439d3af0819af6c55a709 Mon Sep 17 00:00:00 2001 From: fanfpy Date: Tue, 1 Jul 2025 17:04:46 +0800 Subject: [PATCH 12/23] =?UTF-8?q?fix:=20=E5=B0=86Traefik=E8=B7=AF=E7=94=B1?= =?UTF-8?q?=E8=A7=84=E5=88=99=E4=B8=AD=E7=9A=84=E5=8D=95=E5=BC=95=E5=8F=B7?= =?UTF-8?q?=E6=9B=BF=E6=8D=A2=E4=B8=BA=E5=8F=8D=E5=BC=95=E5=8F=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 统一所有服务配置文件中Traefik路由规则的路径前缀引号格式,从单引号改为反引号以保持一致性 --- consul/config/data-service.json | 2 +- consul/config/emotion-service.json | 2 +- consul/config/frontend.json | 2 +- consul/config/quant-service.json | 2 +- consul/config/recommend-service.json | 2 +- consul/config/user-service.json | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/consul/config/data-service.json b/consul/config/data-service.json index a70e02d..3abf2e8 100644 --- a/consul/config/data-service.json +++ b/consul/config/data-service.json @@ -9,7 +9,7 @@ "id": "data-service-1", "tags": [ "traefik.enable=true", - "traefik.http.routers.data-service.rule=PathPrefix('/api/data')", + "traefik.http.routers.data-service.rule=PathPrefix(`/api/data`)", "traefik.http.routers.data-service.entrypoints=web" ], "name": "data-service", diff --git a/consul/config/emotion-service.json b/consul/config/emotion-service.json index fa6e12a..ed41d81 100644 --- a/consul/config/emotion-service.json +++ b/consul/config/emotion-service.json @@ -9,7 +9,7 @@ "id": "emotion-service-1", "tags": [ "traefik.enable=true", - "traefik.http.routers.emotion-service.rule=PathPrefix('/api/emotion')", + "traefik.http.routers.emotion-service.rule=PathPrefix(`/api/emotion`)", "traefik.http.routers.emotion-service.entrypoints=web" ], "name": "emotion-service", diff --git a/consul/config/frontend.json b/consul/config/frontend.json index 50825fb..c0c512a 100644 --- a/consul/config/frontend.json +++ b/consul/config/frontend.json @@ -9,7 +9,7 @@ "id": "frontend-1", "tags": [ "traefik.enable=true", - "traefik.http.routers.frontend.rule=PathPrefix('/')", + "traefik.http.routers.frontend.rule=PathPrefix(`/`)", "traefik.http.routers.frontend.entrypoints=web" ], "name": "frontend", diff --git a/consul/config/quant-service.json b/consul/config/quant-service.json index faff493..bcff10f 100644 --- a/consul/config/quant-service.json +++ b/consul/config/quant-service.json @@ -9,7 +9,7 @@ "id": "quant-service-1", "tags": [ "traefik.enable=true", - "traefik.http.routers.quant-service.rule=PathPrefix('/api/quant')", + "traefik.http.routers.quant-service.rule=PathPrefix(`/api/quant`)", "traefik.http.routers.quant-service.entrypoints=web" ], "name": "quant-service", diff --git a/consul/config/recommend-service.json b/consul/config/recommend-service.json index b277a6f..098c2cb 100644 --- a/consul/config/recommend-service.json +++ b/consul/config/recommend-service.json @@ -9,7 +9,7 @@ "id": "recommend-service-1", "tags": [ "traefik.enable=true", - "traefik.http.routers.recommend-service.rule=PathPrefix('/api/recommend')", + "traefik.http.routers.recommend-service.rule=PathPrefix(`/api/recommend`)", "traefik.http.routers.recommend-service.entrypoints=web" ], "name": "recommend-service", diff --git a/consul/config/user-service.json b/consul/config/user-service.json index 37c25a8..fbbcf9c 100644 --- a/consul/config/user-service.json +++ b/consul/config/user-service.json @@ -9,7 +9,7 @@ "id": "user-service-1", "tags": [ "traefik.enable=true", - "traefik.http.routers.user-service.rule=PathPrefix('/api/user')", + "traefik.http.routers.user-service.rule=PathPrefix(`/api/user`)", "traefik.http.routers.user-service.entrypoints=web" ], "name": "user-service", From f98650118c0c61a399fb154954bdf2070f796f05 Mon Sep 17 00:00:00 2001 From: fanfpy Date: Tue, 1 Jul 2025 22:13:55 +0800 Subject: [PATCH 13/23] =?UTF-8?q?feat(traefik):=20=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E8=87=AA=E5=AE=9A=E4=B9=89API=E8=B7=AF=E5=BE=84=E5=89=8D?= =?UTF-8?q?=E7=BC=80=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 为Traefik仪表板API添加prefix配置项,允许自定义API路径前缀以提高安全性 --- traefik/traefik.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/traefik/traefik.yml b/traefik/traefik.yml index 84f204b..c6dbeb6 100644 --- a/traefik/traefik.yml +++ b/traefik/traefik.yml @@ -11,4 +11,5 @@ providers: api: dashboard: true - insecure: true \ No newline at end of file + insecure: true + prefix: "/traefik-api" # 自定义 API 路径前缀 \ No newline at end of file From 3ced301ee171605692e074fab5c37e8838cc0378 Mon Sep 17 00:00:00 2001 From: fanfpy Date: Wed, 2 Jul 2025 10:47:22 +0800 Subject: [PATCH 14/23] =?UTF-8?q?refactor(traefik):=20=E7=A7=BB=E9=99=A4AP?= =?UTF-8?q?I=E8=B7=AF=E5=BE=84=E5=89=8D=E7=BC=80=E5=B9=B6=E7=BB=9F?= =?UTF-8?q?=E4=B8=80=E6=9C=8D=E5=8A=A1=E8=B7=AF=E7=94=B1=E8=B7=AF=E5=BE=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 将Traefik的API自定义路径前缀移除,并统一各服务的路由路径格式,从`/api/service`改为`/api-service`,提高路径一致性 --- consul/config/data-service.json | 2 +- consul/config/emotion-service.json | 2 +- consul/config/recommend-service.json | 2 +- consul/config/user-service.json | 2 +- traefik/traefik.yml | 3 +-- 5 files changed, 5 insertions(+), 6 deletions(-) diff --git a/consul/config/data-service.json b/consul/config/data-service.json index 3abf2e8..3eafe98 100644 --- a/consul/config/data-service.json +++ b/consul/config/data-service.json @@ -9,7 +9,7 @@ "id": "data-service-1", "tags": [ "traefik.enable=true", - "traefik.http.routers.data-service.rule=PathPrefix(`/api/data`)", + "traefik.http.routers.data-service.rule=PathPrefix(`/api-data`)", "traefik.http.routers.data-service.entrypoints=web" ], "name": "data-service", diff --git a/consul/config/emotion-service.json b/consul/config/emotion-service.json index ed41d81..cf69960 100644 --- a/consul/config/emotion-service.json +++ b/consul/config/emotion-service.json @@ -9,7 +9,7 @@ "id": "emotion-service-1", "tags": [ "traefik.enable=true", - "traefik.http.routers.emotion-service.rule=PathPrefix(`/api/emotion`)", + "traefik.http.routers.emotion-service.rule=PathPrefix(`/api-emotion`)", "traefik.http.routers.emotion-service.entrypoints=web" ], "name": "emotion-service", diff --git a/consul/config/recommend-service.json b/consul/config/recommend-service.json index 098c2cb..6bfbf3a 100644 --- a/consul/config/recommend-service.json +++ b/consul/config/recommend-service.json @@ -9,7 +9,7 @@ "id": "recommend-service-1", "tags": [ "traefik.enable=true", - "traefik.http.routers.recommend-service.rule=PathPrefix(`/api/recommend`)", + "traefik.http.routers.recommend-service.rule=PathPrefix(`/api-recommend`)", "traefik.http.routers.recommend-service.entrypoints=web" ], "name": "recommend-service", diff --git a/consul/config/user-service.json b/consul/config/user-service.json index fbbcf9c..c293f9d 100644 --- a/consul/config/user-service.json +++ b/consul/config/user-service.json @@ -9,7 +9,7 @@ "id": "user-service-1", "tags": [ "traefik.enable=true", - "traefik.http.routers.user-service.rule=PathPrefix(`/api/user`)", + "traefik.http.routers.user-service.rule=PathPrefix(`/api-user`)", "traefik.http.routers.user-service.entrypoints=web" ], "name": "user-service", diff --git a/traefik/traefik.yml b/traefik/traefik.yml index c6dbeb6..84f204b 100644 --- a/traefik/traefik.yml +++ b/traefik/traefik.yml @@ -11,5 +11,4 @@ providers: api: dashboard: true - insecure: true - prefix: "/traefik-api" # 自定义 API 路径前缀 \ No newline at end of file + insecure: true \ No newline at end of file From cebc343893ab424d4128a41e5ab0c363dbfffa78 Mon Sep 17 00:00:00 2001 From: fanfpy Date: Wed, 2 Jul 2025 14:44:29 +0800 Subject: [PATCH 15/23] =?UTF-8?q?refactor(traefik):=20=E7=BB=9F=E4=B8=80AP?= =?UTF-8?q?I=E8=B7=AF=E5=BE=84=E5=89=8D=E7=BC=80=E5=B9=B6=E8=B0=83?= =?UTF-8?q?=E6=95=B4=E6=9C=8D=E5=8A=A1=E8=B7=AF=E7=94=B1=E8=A7=84=E5=88=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 为traefik仪表板API添加路径前缀/traefik-api - 将前端服务路由路径从/改为/frontend - 统一数据服务、用户服务、情感服务和推荐服务的API路径为/api/前缀 --- consul/config/data-service.json | 2 +- consul/config/emotion-service.json | 2 +- consul/config/frontend.json | 2 +- consul/config/recommend-service.json | 2 +- consul/config/user-service.json | 2 +- traefik/traefik.yml | 3 ++- 6 files changed, 7 insertions(+), 6 deletions(-) diff --git a/consul/config/data-service.json b/consul/config/data-service.json index 3eafe98..3abf2e8 100644 --- a/consul/config/data-service.json +++ b/consul/config/data-service.json @@ -9,7 +9,7 @@ "id": "data-service-1", "tags": [ "traefik.enable=true", - "traefik.http.routers.data-service.rule=PathPrefix(`/api-data`)", + "traefik.http.routers.data-service.rule=PathPrefix(`/api/data`)", "traefik.http.routers.data-service.entrypoints=web" ], "name": "data-service", diff --git a/consul/config/emotion-service.json b/consul/config/emotion-service.json index cf69960..ed41d81 100644 --- a/consul/config/emotion-service.json +++ b/consul/config/emotion-service.json @@ -9,7 +9,7 @@ "id": "emotion-service-1", "tags": [ "traefik.enable=true", - "traefik.http.routers.emotion-service.rule=PathPrefix(`/api-emotion`)", + "traefik.http.routers.emotion-service.rule=PathPrefix(`/api/emotion`)", "traefik.http.routers.emotion-service.entrypoints=web" ], "name": "emotion-service", diff --git a/consul/config/frontend.json b/consul/config/frontend.json index c0c512a..5ad7795 100644 --- a/consul/config/frontend.json +++ b/consul/config/frontend.json @@ -9,7 +9,7 @@ "id": "frontend-1", "tags": [ "traefik.enable=true", - "traefik.http.routers.frontend.rule=PathPrefix(`/`)", + "traefik.http.routers.frontend.rule=PathPrefix(`/frontend`)", "traefik.http.routers.frontend.entrypoints=web" ], "name": "frontend", diff --git a/consul/config/recommend-service.json b/consul/config/recommend-service.json index 6bfbf3a..098c2cb 100644 --- a/consul/config/recommend-service.json +++ b/consul/config/recommend-service.json @@ -9,7 +9,7 @@ "id": "recommend-service-1", "tags": [ "traefik.enable=true", - "traefik.http.routers.recommend-service.rule=PathPrefix(`/api-recommend`)", + "traefik.http.routers.recommend-service.rule=PathPrefix(`/api/recommend`)", "traefik.http.routers.recommend-service.entrypoints=web" ], "name": "recommend-service", diff --git a/consul/config/user-service.json b/consul/config/user-service.json index c293f9d..fbbcf9c 100644 --- a/consul/config/user-service.json +++ b/consul/config/user-service.json @@ -9,7 +9,7 @@ "id": "user-service-1", "tags": [ "traefik.enable=true", - "traefik.http.routers.user-service.rule=PathPrefix(`/api-user`)", + "traefik.http.routers.user-service.rule=PathPrefix(`/api/user`)", "traefik.http.routers.user-service.entrypoints=web" ], "name": "user-service", diff --git a/traefik/traefik.yml b/traefik/traefik.yml index 84f204b..1d6a00a 100644 --- a/traefik/traefik.yml +++ b/traefik/traefik.yml @@ -11,4 +11,5 @@ providers: api: dashboard: true - insecure: true \ No newline at end of file + insecure: true + pathPrefix: "/traefik-api" \ No newline at end of file From 6ecb0603bbcd01bc097ccdcbfba3eb421cd43615 Mon Sep 17 00:00:00 2001 From: fanfpy Date: Wed, 2 Jul 2025 17:37:18 +0800 Subject: [PATCH 16/23] =?UTF-8?q?fix(traefik/consul):=20=E7=BB=9F=E4=B8=80?= =?UTF-8?q?=E8=B7=AF=E5=BE=84=E8=A7=84=E5=88=99=E8=AF=AD=E6=B3=95=E5=B9=B6?= =?UTF-8?q?=E6=9B=B4=E6=96=B0API=E8=B7=AF=E5=BE=84=E5=89=8D=E7=BC=80?= =?UTF-8?q?=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 将Traefik路由规则中的路径语法从反引号(`)改为双引号(")以保持一致性 同时将traefik.yml中的pathPrefix改为pathPrefixes以支持数组格式 --- consul/config/data-service.json | 2 +- consul/config/emotion-service.json | 2 +- consul/config/frontend.json | 2 +- consul/config/quant-service.json | 2 +- consul/config/recommend-service.json | 2 +- consul/config/user-service.json | 2 +- consul/config/whoami.json | 2 +- traefik/traefik.yml | 2 +- 8 files changed, 8 insertions(+), 8 deletions(-) diff --git a/consul/config/data-service.json b/consul/config/data-service.json index 3abf2e8..5647c89 100644 --- a/consul/config/data-service.json +++ b/consul/config/data-service.json @@ -9,7 +9,7 @@ "id": "data-service-1", "tags": [ "traefik.enable=true", - "traefik.http.routers.data-service.rule=PathPrefix(`/api/data`)", + "traefik.http.routers.data-service.rule=PathPrefix(\"/api/data\")", "traefik.http.routers.data-service.entrypoints=web" ], "name": "data-service", diff --git a/consul/config/emotion-service.json b/consul/config/emotion-service.json index ed41d81..4346591 100644 --- a/consul/config/emotion-service.json +++ b/consul/config/emotion-service.json @@ -9,7 +9,7 @@ "id": "emotion-service-1", "tags": [ "traefik.enable=true", - "traefik.http.routers.emotion-service.rule=PathPrefix(`/api/emotion`)", + "traefik.http.routers.emotion-service.rule=PathPrefix(\"/api/emotion\")", "traefik.http.routers.emotion-service.entrypoints=web" ], "name": "emotion-service", diff --git a/consul/config/frontend.json b/consul/config/frontend.json index 5ad7795..9263a19 100644 --- a/consul/config/frontend.json +++ b/consul/config/frontend.json @@ -9,7 +9,7 @@ "id": "frontend-1", "tags": [ "traefik.enable=true", - "traefik.http.routers.frontend.rule=PathPrefix(`/frontend`)", + "traefik.http.routers.frontend.rule=PathPrefix(\"/frontend\")", "traefik.http.routers.frontend.entrypoints=web" ], "name": "frontend", diff --git a/consul/config/quant-service.json b/consul/config/quant-service.json index bcff10f..521438d 100644 --- a/consul/config/quant-service.json +++ b/consul/config/quant-service.json @@ -9,7 +9,7 @@ "id": "quant-service-1", "tags": [ "traefik.enable=true", - "traefik.http.routers.quant-service.rule=PathPrefix(`/api/quant`)", + "traefik.http.routers.quant-service.rule=PathPrefix(\"/api/quant\")", "traefik.http.routers.quant-service.entrypoints=web" ], "name": "quant-service", diff --git a/consul/config/recommend-service.json b/consul/config/recommend-service.json index 098c2cb..317ff02 100644 --- a/consul/config/recommend-service.json +++ b/consul/config/recommend-service.json @@ -9,7 +9,7 @@ "id": "recommend-service-1", "tags": [ "traefik.enable=true", - "traefik.http.routers.recommend-service.rule=PathPrefix(`/api/recommend`)", + "traefik.http.routers.recommend-service.rule=PathPrefix(\"/api/recommend\")", "traefik.http.routers.recommend-service.entrypoints=web" ], "name": "recommend-service", diff --git a/consul/config/user-service.json b/consul/config/user-service.json index fbbcf9c..dfbbb68 100644 --- a/consul/config/user-service.json +++ b/consul/config/user-service.json @@ -9,7 +9,7 @@ "id": "user-service-1", "tags": [ "traefik.enable=true", - "traefik.http.routers.user-service.rule=PathPrefix(`/api/user`)", + "traefik.http.routers.user-service.rule=PathPrefix(\"/api/user\")", "traefik.http.routers.user-service.entrypoints=web" ], "name": "user-service", diff --git a/consul/config/whoami.json b/consul/config/whoami.json index 6d47134..93eda8c 100644 --- a/consul/config/whoami.json +++ b/consul/config/whoami.json @@ -4,7 +4,7 @@ "tags": [ "traefik.enable=true", "traefik.http.routers.whoami.entrypoints=web", - "traefik.http.routers.whoami.rule=Path(`/whoami`)", + "traefik.http.routers.whoami.rule=Path(\"/whoami\")", "traefik.http.services.whoami.loadbalancer.server.port=80" ], "address": "whoami", diff --git a/traefik/traefik.yml b/traefik/traefik.yml index 1d6a00a..473e93c 100644 --- a/traefik/traefik.yml +++ b/traefik/traefik.yml @@ -12,4 +12,4 @@ providers: api: dashboard: true insecure: true - pathPrefix: "/traefik-api" \ No newline at end of file + pathPrefixes: ["/traefik-api"] \ No newline at end of file From ca930f281bfc8147d86fd4fc71f4a155294f762f Mon Sep 17 00:00:00 2001 From: fanfpy Date: Sun, 6 Jul 2025 12:03:08 +0800 Subject: [PATCH 17/23] =?UTF-8?q?=E5=88=A0=E9=99=A4=E4=B8=8D=E5=BF=85?= =?UTF-8?q?=E8=A6=81=E7=9A=84=E6=8E=A5=E5=8F=A3=E8=BD=AC=E6=8D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- traefik/traefik.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/traefik/traefik.yml b/traefik/traefik.yml index 473e93c..84f204b 100644 --- a/traefik/traefik.yml +++ b/traefik/traefik.yml @@ -11,5 +11,4 @@ providers: api: dashboard: true - insecure: true - pathPrefixes: ["/traefik-api"] \ No newline at end of file + insecure: true \ No newline at end of file From 90a9fff1f01c46111d965eae378f54c39128d2e8 Mon Sep 17 00:00:00 2001 From: fanfpy Date: Sun, 6 Jul 2025 12:16:51 +0800 Subject: [PATCH 18/23] =?UTF-8?q?fix(consul):=20=E6=B7=BB=E5=8A=A0traefik?= =?UTF-8?q?=E4=B8=AD=E9=97=B4=E4=BB=B6=E4=BB=A5=E9=87=8D=E5=86=99data-serv?= =?UTF-8?q?ice=E8=B7=AF=E5=BE=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 添加路径重写中间件规则,将/api/data/路径重定向到/api/public/,以解决API路径不一致问题 --- consul/config/data-service.json | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/consul/config/data-service.json b/consul/config/data-service.json index 5647c89..29fd51b 100644 --- a/consul/config/data-service.json +++ b/consul/config/data-service.json @@ -10,7 +10,10 @@ "tags": [ "traefik.enable=true", "traefik.http.routers.data-service.rule=PathPrefix(\"/api/data\")", - "traefik.http.routers.data-service.entrypoints=web" + "traefik.http.routers.data-service.entrypoints=web", + "traefik.http.middlewares.data-service-rewrite.replacepathregex.regex=^/api/data/(.*)", + "traefik.http.middlewares.data-service-rewrite.replacepathregex.replacement=/api/public/$1", + "traefik.http.routers.data-service.middlewares=data-service-rewrite" ], "name": "data-service", "port": 8000 From de5d14befb83db39e1f35caec772bbd304117717 Mon Sep 17 00:00:00 2001 From: fanfpy Date: Sun, 6 Jul 2025 12:19:20 +0800 Subject: [PATCH 19/23] =?UTF-8?q?refactor(consul):=20=E7=A7=BB=E9=99=A4dat?= =?UTF-8?q?a-service=E4=B8=AD=E5=86=97=E4=BD=99=E7=9A=84traefik=E9=87=8D?= =?UTF-8?q?=E5=86=99=E8=A7=84=E5=88=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 移除不再需要的路径重写中间件配置,简化服务路由设置 --- consul/config/data-service.json | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/consul/config/data-service.json b/consul/config/data-service.json index 29fd51b..5647c89 100644 --- a/consul/config/data-service.json +++ b/consul/config/data-service.json @@ -10,10 +10,7 @@ "tags": [ "traefik.enable=true", "traefik.http.routers.data-service.rule=PathPrefix(\"/api/data\")", - "traefik.http.routers.data-service.entrypoints=web", - "traefik.http.middlewares.data-service-rewrite.replacepathregex.regex=^/api/data/(.*)", - "traefik.http.middlewares.data-service-rewrite.replacepathregex.replacement=/api/public/$1", - "traefik.http.routers.data-service.middlewares=data-service-rewrite" + "traefik.http.routers.data-service.entrypoints=web" ], "name": "data-service", "port": 8000 From 5af50cc066c80dd1f96a2f9ffb5405caba3a75d5 Mon Sep 17 00:00:00 2001 From: fanfpy Date: Sun, 6 Jul 2025 12:28:20 +0800 Subject: [PATCH 20/23] =?UTF-8?q?fix(consul):=20=E6=B7=BB=E5=8A=A0Traefik?= =?UTF-8?q?=E4=B8=AD=E9=97=B4=E4=BB=B6=E4=BB=A5=E5=89=A5=E7=A6=BB/api/data?= =?UTF-8?q?=E5=89=8D=E7=BC=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 添加stripprefix中间件配置,确保请求路由到data-service时剥离/api/data前缀,避免路径不匹配问题 --- consul/config/data-service.json | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/consul/config/data-service.json b/consul/config/data-service.json index 5647c89..16bfa16 100644 --- a/consul/config/data-service.json +++ b/consul/config/data-service.json @@ -10,7 +10,9 @@ "tags": [ "traefik.enable=true", "traefik.http.routers.data-service.rule=PathPrefix(\"/api/data\")", - "traefik.http.routers.data-service.entrypoints=web" + "traefik.http.routers.data-service.entrypoints=web", + "traefik.http.middlewares.data-service-strip.stripprefix.prefixes=/api/data", + "traefik.http.routers.data-service.middlewares=data-service-strip" ], "name": "data-service", "port": 8000 From dc04f20856f40e76f975515048a617d8ef1c7e5c Mon Sep 17 00:00:00 2001 From: fanfpy Date: Sun, 6 Jul 2025 12:42:38 +0800 Subject: [PATCH 21/23] =?UTF-8?q?fix(traefik):=20=E4=BF=AE=E6=AD=A3?= =?UTF-8?q?=E6=9C=8D=E5=8A=A1=E7=AB=AF=E5=8F=A3=E6=B3=A8=E9=87=8A=E5=B9=B6?= =?UTF-8?q?=E6=9B=B4=E6=96=B0=E8=B7=AF=E7=94=B1=E8=A7=84=E5=88=99=E4=B8=BA?= =?UTF-8?q?=E5=9F=BA=E4=BA=8E=E5=9F=9F=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 将docker-compose.yml中的错误注释修正为服务端口注释 将所有服务的路由规则从PathPrefix改为基于域名的Host规则 移除data-service中不再需要的路径前缀中间件配置 --- consul/config/data-service.json | 6 ++---- consul/config/emotion-service.json | 2 +- consul/config/frontend.json | 2 +- consul/config/quant-service.json | 2 +- consul/config/recommend-service.json | 2 +- consul/config/user-service.json | 2 +- docker-compose.yml | 2 +- 7 files changed, 8 insertions(+), 10 deletions(-) diff --git a/consul/config/data-service.json b/consul/config/data-service.json index 16bfa16..149ae67 100644 --- a/consul/config/data-service.json +++ b/consul/config/data-service.json @@ -9,10 +9,8 @@ "id": "data-service-1", "tags": [ "traefik.enable=true", - "traefik.http.routers.data-service.rule=PathPrefix(\"/api/data\")", - "traefik.http.routers.data-service.entrypoints=web", - "traefik.http.middlewares.data-service-strip.stripprefix.prefixes=/api/data", - "traefik.http.routers.data-service.middlewares=data-service-strip" + "traefik.http.routers.data-service.rule=Host(\"data.aristockai.com\")", + "traefik.http.routers.data-service.entrypoints=web" ], "name": "data-service", "port": 8000 diff --git a/consul/config/emotion-service.json b/consul/config/emotion-service.json index 4346591..0919352 100644 --- a/consul/config/emotion-service.json +++ b/consul/config/emotion-service.json @@ -9,7 +9,7 @@ "id": "emotion-service-1", "tags": [ "traefik.enable=true", - "traefik.http.routers.emotion-service.rule=PathPrefix(\"/api/emotion\")", + "traefik.http.routers.emotion-service.rule=Host(\"emotion.aristockai.com\")", "traefik.http.routers.emotion-service.entrypoints=web" ], "name": "emotion-service", diff --git a/consul/config/frontend.json b/consul/config/frontend.json index 9263a19..e191e41 100644 --- a/consul/config/frontend.json +++ b/consul/config/frontend.json @@ -9,7 +9,7 @@ "id": "frontend-1", "tags": [ "traefik.enable=true", - "traefik.http.routers.frontend.rule=PathPrefix(\"/frontend\")", + "traefik.http.routers.frontend.rule=Host(\"aristockai.com\") || Host(\"www.aristockai.com\")", "traefik.http.routers.frontend.entrypoints=web" ], "name": "frontend", diff --git a/consul/config/quant-service.json b/consul/config/quant-service.json index 521438d..ef7a1ea 100644 --- a/consul/config/quant-service.json +++ b/consul/config/quant-service.json @@ -9,7 +9,7 @@ "id": "quant-service-1", "tags": [ "traefik.enable=true", - "traefik.http.routers.quant-service.rule=PathPrefix(\"/api/quant\")", + "traefik.http.routers.quant-service.rule=Host(\"quant.aristockai.com\")", "traefik.http.routers.quant-service.entrypoints=web" ], "name": "quant-service", diff --git a/consul/config/recommend-service.json b/consul/config/recommend-service.json index 317ff02..61dfe90 100644 --- a/consul/config/recommend-service.json +++ b/consul/config/recommend-service.json @@ -9,7 +9,7 @@ "id": "recommend-service-1", "tags": [ "traefik.enable=true", - "traefik.http.routers.recommend-service.rule=PathPrefix(\"/api/recommend\")", + "traefik.http.routers.recommend-service.rule=Host(\"recommend.aristockai.com\")", "traefik.http.routers.recommend-service.entrypoints=web" ], "name": "recommend-service", diff --git a/consul/config/user-service.json b/consul/config/user-service.json index dfbbb68..0384d27 100644 --- a/consul/config/user-service.json +++ b/consul/config/user-service.json @@ -9,7 +9,7 @@ "id": "user-service-1", "tags": [ "traefik.enable=true", - "traefik.http.routers.user-service.rule=PathPrefix(\"/api/user\")", + "traefik.http.routers.user-service.rule=Host(\"user.aristockai.com\")", "traefik.http.routers.user-service.entrypoints=web" ], "name": "user-service", diff --git a/docker-compose.yml b/docker-compose.yml index f0d786d..babba39 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -42,7 +42,7 @@ services: container_name: ari-data-service restart: always ports: - - "8000:8000" # Traefik dashboard + - "8000:8000" # 错误:应为服务端口注释而非Traefik dashboard networks: - microservice-network environment: From 611a26a59a0b734e08d632ec4faf8ca85e56f8c0 Mon Sep 17 00:00:00 2001 From: fanfpy Date: Sun, 6 Jul 2025 16:19:32 +0800 Subject: [PATCH 22/23] =?UTF-8?q?refactor(config):=20=E9=87=8D=E6=9E=84?= =?UTF-8?q?=E9=85=8D=E7=BD=AE=E6=96=87=E4=BB=B6=E7=BB=93=E6=9E=84=E4=B8=BA?= =?UTF-8?q?=E7=8E=AF=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 From 78b68466b4c260cccf57b95a288ac499ea740966 Mon Sep 17 00:00:00 2001 From: fanfpy Date: Sun, 6 Jul 2025 16:28:25 +0800 Subject: [PATCH 23/23] =?UTF-8?q?chore:=20=E4=B8=BAdev=E5=92=8Cprod?= =?UTF-8?q?=E7=8E=AF=E5=A2=83=E6=B7=BB=E5=8A=A0consul=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E7=9B=AE=E5=BD=95=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- consul/config/dev/consul.json | 1 + consul/config/prod/consul.json | 1 + 2 files changed, 2 insertions(+) diff --git a/consul/config/dev/consul.json b/consul/config/dev/consul.json index 45575db..1e8f996 100644 --- a/consul/config/dev/consul.json +++ b/consul/config/dev/consul.json @@ -1,4 +1,5 @@ { + "data_dir": "/consul/data", "acl": { "default_policy": "deny", "enabled": false diff --git a/consul/config/prod/consul.json b/consul/config/prod/consul.json index 0aa6a91..b10dc23 100644 --- a/consul/config/prod/consul.json +++ b/consul/config/prod/consul.json @@ -1,4 +1,5 @@ { + "data_dir": "/consul/data", "acl": { "default_policy": "deny", "enabled": true