From 0ee60843f835ba62df2bf42d189d314213b764a4 Mon Sep 17 00:00:00 2001 From: dingzhaojun Date: Wed, 1 Nov 2023 21:26:54 +0800 Subject: [PATCH] traefik --- compose-demo01-jib.yml | 8 +- compose-demo01-jvm.yml | 5 +- compose-demo01-native.yml | 5 +- compose-traefik.yml | 59 ++++++++++++ compose.yml | 90 ++++++++++++++++--- readme.txt | 6 -- .../demo/controller/UserController.java | 7 +- 7 files changed, 157 insertions(+), 23 deletions(-) create mode 100644 compose-traefik.yml diff --git a/compose-demo01-jib.yml b/compose-demo01-jib.yml index 383b712..7fa3ead 100644 --- a/compose-demo01-jib.yml +++ b/compose-demo01-jib.yml @@ -1,9 +1,10 @@ version: '3.9' -name: demo01 +name: demo01-jib services: demo01-jib: image: svn.youshengyun.com:9923/demo01-jib:1.0 container_name: demo01-jib + hostname: demo01-jib restart: unless-stopped extra_hosts: - "host.docker.internal:host-gateway" @@ -17,6 +18,11 @@ services: - "traefik.enable=true" - "traefik.http.routers.demo01-jib.entrypoints=web" - "traefik.http.routers.demo01-jib.rule=PathPrefix(`/demo01`)" + - "traefik.http.services.demo01.loadbalancer.server.scheme=http" + - "traefik.http.services.demo01.loadbalancer.server.port=7055" + + - "traefik.http.routers.demo01-jib-ssl.entrypoints=web-ssl" + - "traefik.http.routers.demo01-jib-ssl.rule=PathPrefix(`/demo01`)" networks: y9-share-net: diff --git a/compose-demo01-jvm.yml b/compose-demo01-jvm.yml index f172b2a..f2105c8 100644 --- a/compose-demo01-jvm.yml +++ b/compose-demo01-jvm.yml @@ -1,9 +1,10 @@ version: '3.9' -name: demo01 +name: demo01-jvm services: demo01-jvm: image: svn.youshengyun.com:9923/demo01-jvm:1.0 container_name: demo01-jvm + hostname: demo01-jvm restart: unless-stopped extra_hosts: - "host.docker.internal:host-gateway" @@ -17,6 +18,8 @@ services: - "traefik.enable=true" - "traefik.http.routers.demo01-jvm.entrypoints=web" - "traefik.http.routers.demo01-jvm.rule=PathPrefix(`/demo01`)" + - "traefik.http.services.demo01.loadbalancer.server.scheme=http" + - "traefik.http.services.demo01.loadbalancer.server.port=7055" networks: y9-share-net: diff --git a/compose-demo01-native.yml b/compose-demo01-native.yml index 4fad11c..ba1c6b0 100644 --- a/compose-demo01-native.yml +++ b/compose-demo01-native.yml @@ -1,9 +1,10 @@ version: '3.9' -name: demo01 +name: demo01-native services: demo01-native: image: svn.youshengyun.com:9924/demo01-native:1.0 container_name: demo01-native + hostname: demo01-native restart: unless-stopped extra_hosts: - "host.docker.internal:host-gateway" @@ -17,6 +18,8 @@ services: - "traefik.enable=true" - "traefik.http.routers.demo01-native.entrypoints=web" - "traefik.http.routers.demo01-native.rule=PathPrefix(`/demo01`)" + - "traefik.http.services.demo01.loadbalancer.server.scheme=http" + - "traefik.http.services.demo01.loadbalancer.server.port=7055" networks: y9-share-net: diff --git a/compose-traefik.yml b/compose-traefik.yml new file mode 100644 index 0000000..10f4afd --- /dev/null +++ b/compose-traefik.yml @@ -0,0 +1,59 @@ +version: '3.9' +name: traefik +services: + traefik: + image: traefik:latest + container_name: traefik01 + hostname: traefik + restart: unless-stopped + extra_hosts: + - "host.docker.internal:host-gateway" + networks: + - y9-share-net + ports: + - "8081:8081" + - "8080:8080" + - "443:443" + volumes: + # Allows Traefik can listen to the Docker events + - "/var/run/docker.sock:/var/run/docker.sock" + # Mount the directory containing the certs + - "d:/docker-config/traefik/certs:/etc/certs/" + # Mount the dynamic configuration + - "d:/docker-config/traefik/dynamic/certs-traefik.yaml:/etc/traefik/dynamic/certs-traefik.yaml" + command: + - "--global.sendanonymoususage=false" + - "--global.checknewversion=false" + - "--api=true" + - "--api.dashboard=true" + - "--api.insecure=true" + - "--api.debug=false" + - "--ping=true" + - "--log.level=INFO" + - "--log.format=common" + - "--accesslog=false" + - "--entrypoints.web.address=:8081" + - "--entrypoints.web-ssl.address=:443" + - "--entrypoints.traefik.address=:8080" + - "--providers.docker=true" + - "--providers.docker.watch=true" + - "--providers.docker.exposedbydefault=false" + - "--providers.docker.endpoint=unix:///var/run/docker.sock" + - "--providers.docker.useBindPortIP=false" + - "--providers.docker.network=y9-share-net" + - "--providers.file=true" + - "--providers.file.watch=true" + - "--providers.file.directory=/etc/traefik/dynamic" + - "--providers.file.debugloggeneratedtemplate=true" + healthcheck: + test: ["CMD-SHELL", "wget -q --spider --proxy off localhost:8080/ping || exit 1"] + interval: 5s + retries: 10 + logging: + driver: "json-file" + options: + max-size: "1m" + +networks: + y9-share-net: + external: true \ No newline at end of file diff --git a/compose.yml b/compose.yml index 1ee7318..69833e8 100644 --- a/compose.yml +++ b/compose.yml @@ -38,7 +38,7 @@ services: command: redis-server --requirepass "12345678" volumes: - d:/docker-data/redis:/data - + consul: image: docker.io/bitnami/consul:latest container_name: consul01 @@ -53,17 +53,87 @@ services: - CONSUL_ENABLE_UI=true - CONSUL_HTTP_PORT_NUMBER=8500 ports: - #- '8300:8300' - #- '8301:8301' - #- '8301:8301/udp' + - '8300:8300' + - '8301:8301' + - '8301:8301/udp' - '8500:8500' - #- '8600:8600' - #- '8600:8600/udp' + - '8600:8600' + - '8600:8600/udp' volumes: - d:/docker-data/consul:/bitnami/consul - + + elasticsearch: + image: elasticsearch:8.10.2 + container_name: elastic01 + restart: always + extra_hosts: + - "host.docker.internal:host-gateway" + networks: + - y9-share-net + ports: + - '9200:9200' + - '9300:9300' + volumes: + - d:/docker-data/es:/usr/share/elasticsearch/data + environment: + - discovery.type=single-node + - xpack.security.enabled=false + labels: + org.springframework.boot.service-connection: elasticsearch + + kafka: + image: bitnami/kafka:latest + container_name: kafka01 + restart: always + extra_hosts: + - "host.docker.internal:host-gateway" + networks: + - y9-share-net + ports: + - "9092:9092" + - "9094:9094" + environment: + - KAFKA_CFG_NODE_ID=0 + - KAFKA_CFG_PROCESS_ROLES=controller,broker + - KAFKA_CFG_LISTENERS=PLAINTEXT://:9092,CONTROLLER://:9093,EXTERNAL://0.0.0.0:9094 + - KAFKA_CFG_ADVERTISED_LISTENERS=PLAINTEXT://kafka:9092,EXTERNAL://localhost:9094 + - KAFKA_CFG_LISTENER_SECURITY_PROTOCOL_MAP=CONTROLLER:PLAINTEXT,EXTERNAL:PLAINTEXT,PLAINTEXT:PLAINTEXT + - KAFKA_CFG_CONTROLLER_LISTENER_NAMES=CONTROLLER + - KAFKA_CFG_CONTROLLER_QUORUM_VOTERS=0@kafka:9093 + volumes: + - d:/docker-data/kafka:/bitnami/kafka + + nacos: + image: nacos/nacos-server:v2.2.3 + container_name: nacos01 + restart: always + extra_hosts: + - "host.docker.internal:host-gateway" + networks: + - y9-share-net + ports: + - "8848:8848" + - "9848:9848" + depends_on: + db: + condition: service_healthy + environment: + - PREFER_HOST_MODE=hostname + - MODE=standalone + - SPRING_DATASOURCE_PLATFORM=mysql + - MYSQL_SERVICE_HOST=db + - MYSQL_SERVICE_DB_NAME=nacos + - MYSQL_SERVICE_PORT=3306 + - MYSQL_SERVICE_USER=root + - MYSQL_SERVICE_PASSWORD=12345678 + - MYSQL_SERVICE_DB_PARAM=characterEncoding=utf8&connectTimeout=1000&socketTimeout=3000&autoReconnect=true&useSSL=false&allowPublicKeyRetrieval=true + - NACOS_AUTH_ENABLE=true + - NACOS_AUTH_IDENTITY_KEY=nacos + - NACOS_AUTH_IDENTITY_VALUE=nacos + - NACOS_AUTH_TOKEN=VGhpc0lzTXlDdXN0b21TZWNyZXRLZXkwMTIzNDU2Nzg= + volumes: + - d:/docker-data/nacos-logs:/home/nacos/logs + networks: y9-share-net: - external: true - - + external: true \ No newline at end of file diff --git a/readme.txt b/readme.txt index c14428a..afaa10c 100644 --- a/readme.txt +++ b/readme.txt @@ -2,12 +2,6 @@ ./mvnw.cmd clean spring-boot:build-image -Dmaven.test.skip=true ./mvnw.cmd clean spring-boot:build-image -Pnative -Dmaven.test.skip=true -docker image ls - -docker run --name demo01-jib --net y9-share-net -ti -p 7055:7055 svn.youshengyun.com:9923/demo01-jib:1.0 -docker run --name demo01-jvm --net y9-share-net -ti -p 17055:7055 svn.youshengyun.com:9923/demo01-jvm:1.0 -docker run --name demo01-native --net y9-share-net -ti -p 27055:7055 svn.youshengyun.com:9923/demo01-native:1.0 - docker compose -f compose-demo01-jib.yml up -d docker compose -f compose-demo01-jvm.yml up -d docker compose -f compose-demo01-native.yml up -d diff --git a/src/main/java/net/risesoft/demo/controller/UserController.java b/src/main/java/net/risesoft/demo/controller/UserController.java index 22332e3..9fdcb86 100644 --- a/src/main/java/net/risesoft/demo/controller/UserController.java +++ b/src/main/java/net/risesoft/demo/controller/UserController.java @@ -25,13 +25,12 @@ public class UserController { @GetMapping({"", "/"}) public List hosts(HttpServletRequest request){ List list = new ArrayList(); - list.add("request.getServerName()=" + request.getServerName()); - list.add("request.getLocalAddr() =" + request.getLocalAddr()); - list.add("request.getLocalAddr() =" + request.getLocalName()); + list.add("serverName=" + request.getServerName()); + list.add("localAddr=" + request.getLocalAddr()); return list; } - @GetMapping({"/api/users"}) + @GetMapping({"/users"}) public List users(){ return userRepository.findAll(); }