refactor(consul): 将服务配置从hcl迁移至json格式
迁移所有Consul服务配置从HCL格式到JSON格式,以统一配置管理方式 更新traefik配置以支持Consul服务发现 添加whoami服务用于测试
This commit is contained in:
parent
75e10f5324
commit
e8fac3b536
@ -1,8 +0,0 @@
|
|||||||
ui_config {
|
|
||||||
enabled = true
|
|
||||||
}
|
|
||||||
|
|
||||||
acl {
|
|
||||||
enabled = false
|
|
||||||
default_policy = "deny"
|
|
||||||
}
|
|
||||||
9
consul/config/consul.json
Normal file
9
consul/config/consul.json
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
{
|
||||||
|
"acl": {
|
||||||
|
"default_policy": "deny",
|
||||||
|
"enabled": false
|
||||||
|
},
|
||||||
|
"ui_config": {
|
||||||
|
"enabled": true
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -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`)"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
17
consul/config/data-service.json
Normal file
17
consul/config/data-service.json
Normal file
@ -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
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -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`)"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
17
consul/config/emotion-service.json
Normal file
17
consul/config/emotion-service.json
Normal file
@ -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
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -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(`/`)"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
17
consul/config/frontend.json
Normal file
17
consul/config/frontend.json
Normal file
@ -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
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -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`)"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
17
consul/config/quant-service.json
Normal file
17
consul/config/quant-service.json
Normal file
@ -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
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -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`)"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
17
consul/config/recommend-service.json
Normal file
17
consul/config/recommend-service.json
Normal file
@ -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
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -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`)"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
17
consul/config/user-service.json
Normal file
17
consul/config/user-service.json
Normal file
@ -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
|
||||||
|
}
|
||||||
|
}
|
||||||
11
consul/config/whoami.json
Normal file
11
consul/config/whoami.json
Normal file
@ -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"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -24,31 +24,14 @@ services:
|
|||||||
retries: 3
|
retries: 3
|
||||||
|
|
||||||
traefik:
|
traefik:
|
||||||
image: traefik:v2.9
|
image: traefik:v2.11
|
||||||
container_name: ari-traefik
|
command:
|
||||||
restart: always
|
- --configFile=/etc/traefik/traefik.yml
|
||||||
depends_on:
|
|
||||||
consul:
|
|
||||||
condition: service_healthy
|
|
||||||
ports:
|
ports:
|
||||||
- "80:80" # 主入口
|
- "80:80"
|
||||||
- "8080:8080" # Dashboard
|
- "8080:8080" # Traefik dashboard
|
||||||
volumes:
|
volumes:
|
||||||
- ./traefik/traefik.yml:/etc/traefik/traefik.yml
|
- ./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:
|
data-service:
|
||||||
build: ./services/data-service
|
build: ./services/data-service
|
||||||
@ -135,4 +118,9 @@ services:
|
|||||||
networks:
|
networks:
|
||||||
- microservice-network
|
- microservice-network
|
||||||
environment:
|
environment:
|
||||||
- SERVICE_NAME=frontend
|
- SERVICE_NAME=frontend
|
||||||
|
|
||||||
|
whoami:
|
||||||
|
image: traefik/whoami
|
||||||
|
expose:
|
||||||
|
- "80" # 可选,Traefik 可以自动发现,不暴露到宿主机
|
||||||
|
|||||||
@ -1,7 +1,13 @@
|
|||||||
entryPoints:
|
entryPoints:
|
||||||
web:
|
web:
|
||||||
address: ":80"
|
address: ":80"
|
||||||
http:
|
|
||||||
middlewares:
|
providers:
|
||||||
compress:
|
consulCatalog:
|
||||||
compress: true
|
endpoint:
|
||||||
|
address: "consul:8500"
|
||||||
|
exposedByDefault: false
|
||||||
|
|
||||||
|
api:
|
||||||
|
dashboard: true
|
||||||
|
insecure: true
|
||||||
Loading…
Reference in New Issue
Block a user