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

2019-04-08  本文已影响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/
上一篇下一篇

猜你喜欢

热点阅读