zoukankan      html  css  js  c++  java
  • docker-compose 完整打包发布, 多服务,多节点SPRING CLOUD ,EUREKA 集群

    https://www.cnblogs.com/sweetchildomine/p/7440262.html

    这里不再使用 端口映射的方式,因为不同主机上,Feign 根据 docker hostname访问会有问题.

    把打包的好jar copy到docker镜像里

    有几个服务,就复制几个dockerfile

    Dockerfile

    复制代码
    FROM registry.cn-hangzhou.aliyuncs.com/laizhenwei/jre:8u144
    
    #
    MAINTAINER zhenweilai <181282945@qq.com>
    
    COPY jar /usr/local
    
    RUN cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime &&  
        echo 'Asia/Shanghai' >/etc/timezone
    复制代码

    开启两个eureka,互相注册

    开启两个api服务,

    开启两个app服务.

    开启一个zuul路由服务

    docker-compose

    复制代码
    version: '2'
    services:
      eureka_master:
        build: eurekaserver
        network_mode: "host"
        command: java -jar /usr/local/eurekaserver.jar --spring.profiles.active=test --eureka.instance.hostname=eureka1 --eureka.instance.other-hostname=eureka2 --server.port=8000 --eureka.instance.other-port=8001
        volumes:
         - /usr/local/microservice/log:/usr/local/microservice/log
        restart: always
    
      eureka_backup:
        build: eurekaserver
        network_mode: "host"
        command: java -jar /usr/local/eurekaserver.jar --spring.profiles.active=test --eureka.instance.hostname=eureka2 --eureka.instance.other-hostname=eureka1 --server.port=8001 --eureka.instance.other-port=8000
        volumes:
         - /usr/local/microservice/log:/usr/local/microservice/log
        restart: always
    
      api_8070:
        build: api
        network_mode: "host"
        command: java -jar /usr/local/api.jar --spring.profiles.active=test --server.port=8070
        depends_on:
         - eureka_master
         - eureka_backup
        volumes:
         - /usr/local/microservice/log:/usr/local/microservice/log
        restart: always
    
      api_8071:
        build: api
        network_mode: "host"
        command: java -jar /usr/local/api.jar --spring.profiles.active=test --server.port=8071
        depends_on:
         - eureka_master
         - eureka_backup
        volumes:
         - /usr/local/microservice/log:/usr/local/microservice/log
        restart: always
    
      router:
        build: router
        network_mode: "host"
        command: java -jar /usr/local/router.jar --spring.profiles.active=test --server.port=8088
        depends_on:
         - eureka_master
         - eureka_backup
        volumes:
         - /usr/local/microservice/log:/usr/local/microservice/log
        restart: always
    
    
      app_8060:
        build: app
        network_mode: "host"
        command: java -jar /usr/local/app.jar --spring.profiles.active=test --server.port=8060
        depends_on:
         - eureka_master
         - eureka_backup
        volumes:
         - /usr/local/microservice/log:/usr/local/microservice/log
        restart: always
    
      app_8080:
        build: app
        network_mode: "host"
        command: java -jar /usr/local/app.jar --spring.profiles.active=test --server.port=8080
        depends_on:
         - eureka_master
         - eureka_backup
        volumes:
         - /usr/local/microservice/log:/usr/local/microservice/log
        restart: always
    复制代码

    应用application.yml,注册到两个eureka

    复制代码
    eureka:
      instance:
        appname: app
        instance-id: ${spring.cloud.client.ipAddress}:${server.port}
        #续约更新时间间隔
        lease-renewal-interval-in-seconds: 10
        #续约到期时间
        lease-expiration-duration-in-seconds: 30
      client:
        serviceUrl:
          defaultZone: http://username:password@eureka1:8000/eureka/,http://username:password@eureka2:8001/eureka/
    复制代码

    eureka application.yml

    复制代码
    eureka:
      instance:
         hostname: localhost
         other-port: 8001
         other-hostname: backup
         appname: eureka-server
         instance-id: ${spring.cloud.client.ipAddress}:${server.port}
         lease-expiration-duration-in-seconds: 5
      server:
        #5秒清理一次
        eviction-interval-timer-in-ms: 5
      client:
        register-with-eureka: true
        fetch-registry: true
        service-url:
          defaultZone: http://username:password@${eureka.instance.other-hostname}:${eureka.instance.other-port}/eureka/
    复制代码

    输入命令:docker-compose up --build -d

    复制代码
    Step 1/4 : FROM registry.cn-hangzhou.aliyuncs.com/laizhenwei/jre:8u144
     ---> 1b97d252ae81
    Step 2/4 : MAINTAINER zhenweilai <181282945@qq.com>
     ---> Using cache
     ---> bf31044329be
    Step 3/4 : COPY jar /usr/local
     ---> 7a1be0756dca
    Removing intermediate container 5c45807bbc81
    Step 4/4 : RUN cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime &&     echo 'Asia/Shanghai' >/etc/timezone
     ---> Running in e8988ea8a1f8
     ---> ad26f883175e
    Removing intermediate container e8988ea8a1f8
    Successfully built ad26f883175e
    Successfully tagged microservice_eureka_backup:latest
    Building eureka_master
    Step 1/4 : FROM registry.cn-hangzhou.aliyuncs.com/laizhenwei/jre:8u144
     ---> 1b97d252ae81
    Step 2/4 : MAINTAINER zhenweilai <181282945@qq.com>
     ---> Using cache
     ---> bf31044329be
    Step 3/4 : COPY jar /usr/local
     ---> Using cache
     ---> 7a1be0756dca
    Step 4/4 : RUN cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime &&     echo 'Asia/Shanghai' >/etc/timezone
     ---> Using cache
     ---> ad26f883175e
    Successfully built ad26f883175e
    Successfully tagged microservice_eureka_master:latest
    Building cloudinvoice_8080
    Step 1/4 : FROM registry.cn-hangzhou.aliyuncs.com/laizhenwei/jre:8u144
     ---> 1b97d252ae81
    Step 2/4 : MAINTAINER zhenweilai <181282945@qq.com>
     ---> Using cache
     ---> bf31044329be
    Step 3/4 : COPY jar /usr/local
     ---> Using cache
     ---> b9fe90218b85
    Step 4/4 : RUN cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime &&     echo 'Asia/Shanghai' >/etc/timezone
     ---> Using cache
     ---> 709a728e383a
    Successfully built 709a728e383a
    Successfully tagged microservice_cloudinvoice_8080:latest
    Building cloudinvoice_8060
    Step 1/4 : FROM registry.cn-hangzhou.aliyuncs.com/laizhenwei/jre:8u144
     ---> 1b97d252ae81
    Step 2/4 : MAINTAINER zhenweilai <181282945@qq.com>
     ---> Using cache
     ---> bf31044329be
    Step 3/4 : COPY jar /usr/local
     ---> Using cache
     ---> b9fe90218b85
    Step 4/4 : RUN cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime &&     echo 'Asia/Shanghai' >/etc/timezone
     ---> Using cache
     ---> 709a728e383a
    Successfully built 709a728e383a
    Successfully tagged microservice_cloudinvoice_8060:latest
    Building api_8070
    Step 1/4 : FROM registry.cn-hangzhou.aliyuncs.com/laizhenwei/jre:8u144
     ---> 1b97d252ae81
    Step 2/4 : MAINTAINER zhenweilai <181282945@qq.com>
     ---> Using cache
     ---> bf31044329be
    Step 3/4 : COPY jar /usr/local
     ---> Using cache
     ---> 5b85563136e5
    Step 4/4 : RUN cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime &&     echo 'Asia/Shanghai' >/etc/timezone
     ---> Using cache
     ---> 679564f7d414
    Successfully built 679564f7d414
    Successfully tagged microservice_api_8070:latest
    Building api_8071
    Step 1/4 : FROM registry.cn-hangzhou.aliyuncs.com/laizhenwei/jre:8u144
     ---> 1b97d252ae81
    Step 2/4 : MAINTAINER zhenweilai <181282945@qq.com>
     ---> Using cache
     ---> bf31044329be
    Step 3/4 : COPY jar /usr/local
     ---> Using cache
     ---> 5b85563136e5
    Step 4/4 : RUN cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime &&     echo 'Asia/Shanghai' >/etc/timezone
     ---> Using cache
     ---> 679564f7d414
    Successfully built 679564f7d414
    Successfully tagged microservice_api_8071:latest
    Building router
    Step 1/4 : FROM registry.cn-hangzhou.aliyuncs.com/laizhenwei/jre:8u144
     ---> 1b97d252ae81
    Step 2/4 : MAINTAINER zhenweilai <181282945@qq.com>
     ---> Using cache
     ---> bf31044329be
    Step 3/4 : COPY jar /usr/local
     ---> Using cache
     ---> c88e35c7fc38
    Step 4/4 : RUN cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime &&     echo 'Asia/Shanghai' >/etc/timezone
     ---> Using cache
     ---> 288ce24cfef0
    Successfully built 288ce24cfef0
    Successfully tagged microservice_router:latest
    Recreating microservice_eureka_master_1 ... 
    Recreating microservice_eureka_backup_1 ... 
    Recreating microservice_eureka_master_1
    Recreating microservice_eureka_backup_1 ... done
    Recreating microservice_app_8060_1 ... 
    Recreating microservice_api_8070_1 ... 
    Recreating microservice_api_8070_1
    Recreating microservice_router_1 ... 
    Recreating microservice_api_8071_1 ... 
    Recreating microservice_cloudinvoice_8060_1
    Recreating microservice_api_8071_1
    Recreating microservice_app_8080_1 ... 
    Recreating microservice_router_1
    Recreating microservice_app_8080_1 ... done
    复制代码

    docker-compose ps

    复制代码
                  Name                            Command               State   Ports 
    ---------------------------------------------------------------------------------
    microservice_api_8070_1            java -jar /usr/local/api ...   Up            
    microservice_api_8071_1            java -jar /usr/local/api ...   Up            
    microservice_app_8060_1   java -jar /usr/local/app ...   Up            
    microservice_app_8080_1   java -jar /usr/local/app...   Up            
    microservice_eureka_backup_1       java -jar /usr/local/eurek ...   Up            
    microservice_eureka_master_1       java -jar /usr/local/eurek ...   Up            
    microservice_router_1              java -jar /usr/local/route ...   Up  
    复制代码

     192.168.51.60:8000

  • 相关阅读:
    HDU 5213 分块 容斥
    HDU 2298 三分
    HDU 5144 三分
    HDU 5145 分块 莫队
    HDU 3938 并查集
    HDU 3926 并查集 图同构简单判断 STL
    POJ 2431 优先队列
    HDU 1811 拓扑排序 并查集
    HDU 2685 GCD推导
    HDU 4496 并查集 逆向思维
  • 原文地址:https://www.cnblogs.com/xiaohanlin/p/9286021.html
Copyright © 2011-2022 走看看