美文网首页
eureka在Swarm集群中的多节点部署

eureka在Swarm集群中的多节点部署

作者: 会动的木头疙瘩儿 | 来源:发表于2019-04-08 13:30 被阅读0次

    eureka-server项目application-test.yml的配置文件

    spring:
      application:
        name: eureka-server
    server:
      port: 8761
    
    eureka:
      instance:
        hostname: localhost
      client:
        register-with-eureka: false
        fetch-registry: false
        service-url:
          defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/,${ADDITIONAL_EUREKA_SERVER_LIST}
    

    ADDITIONAL_EUREKA_SERVER_LIST 是定义的环境变量,在容器启动时传入

    eureka-server的docker编排

    version: '3.3'
    services:
      eureka-server1:
        image: 172.16.10.2:5000/test/eureka-server:latest 
        networks:
          test:
            aliases:
              - eureka-server
        ports:
          - "8761:8761"
        environment:
          - ADDITIONAL_EUREKA_SERVER_LIST=http://eureka-server2:8761/eureka/,http://eureka-server3:8761/eureka/
          - "SPRING_PROFILES_ACTIVE=test"
    
      eureka-server2:
        image: 172.16.10.2:5000/test/eureka-server:latest
        networks:
          test:
            aliases:
              - eureka-server
        ports:
          - "8762:8761"
        environment:
          - ADDITIONAL_EUREKA_SERVER_LIST=http://eureka-server1:8761/eureka/,http://eureka-server3:8761/eureka/
          - "SPRING_PROFILES_ACTIVE=test"
    
      eureka-server3:
        image: 172.16.10.2:5000/test/eureka-server:latest
        networks:
          test:
            aliases:
              - eureka-server
        ports:
          - "8763:8761"
        environment:
          - ADDITIONAL_EUREKA_SERVER_LIST=http://eureka-server1:8761/eureka/,http://eureka-server2:8761/eureka/
          - "SPRING_PROFILES_ACTIVE=test"
    
    networks:
      test:
        external: true
    

    image 是用的自建的镜像库 SPRING_PROFILES_ACTIVE是在dockerfile中的变量,为了指定启动环境,如果你的配置文件不区分环境,可以去掉这一行"- SPRING_PROFILES_ACTIVE=test"这里的networks需要提前创建。

    eureka-client的配置

    eureka:
      instance:
        leaseRenewalIntervalInSeconds: 10
        health-check-url-path: /actuator/health
        hostname: all-service
        instance-id: ${spring.application.name}:${random.int}:${server.port}
    
      client:
        registryFetchIntervalSeconds: 5
        service-url:
          defaultZone: http://eureka-server:8761/eureka/
    

    相关文章

      网友评论

          本文标题:eureka在Swarm集群中的多节点部署

          本文链接:https://www.haomeiwen.com/subject/omuuiqtx.html