liangxiaobo / springbootcloud-all

搭建spring cloud的微服务,Eureka、Feign、Ribbon、Hystrix、Hystrix Dashboard、Turbine聚合监控、Zuul
30 stars 13 forks source link

用docker swarm部署 eureka 不能互相注册。能否指点一下呢大佬 #1

Open square-box opened 5 years ago

square-box commented 5 years ago

server: port: 8761

spring: security: user: name: campus password: campus application: name: @artifactId@ cloud: config: enabled: false

docker-compose部署时候 hostname campus-eureka

类似的 redis campus-redis ,gateway 换成 campus-gateway

eureka: instance: hostname: campus-eureka prefer-ip-address: true client: register-with-eureka: false fetch-registry: false service-url: defaultZone: http://campus:campus@campus-eureka:8761/eureka/ server: eviction-interval-timer-in-ms: 4000 enable-self-preservation: false renewal-percent-threshold: 0.9

management: endpoints: web: exposure: include: '*'

liangxiaobo commented 5 years ago

你要用eureka高可用的思路去搭建,不能用一个service多个replicas的方式部署,这样会有问题,eureka之间不能同步, compose这么写:

version: '3.3'

services:
  eureka-server:
    image: 172.16.10.192:5000/eureka-server:latest
    deploy:
      mode: replicated
      replicas: 1
      restart_policy:
        condition: on-failure
    ports:
      - "8761:8761"
    networks:
      my-overlay-network:
        aliases:
          - eureka-server
    environment:
        - "SPRING_PROFILES_ACTIVE=peer1-test"
  eureka-server2:
    image: 172.16.10.192:5000/eureka-server:latest
    deploy:
      mode: replicated
      replicas: 1
      restart_policy:
        condition: on-failure
    ports:
      - "8762:8762"
    networks:
      my-overlay-network:
        aliases:
          - eureka-server2
    depends_on:
      - eureka-server1
    environment:
        - "SPRING_PROFILES_ACTIVE=peer2-test"

  eureka-server3:
    image: 172.16.10.192:5000/eureka-server:latest
    deploy:
      mode: replicated
      replicas: 1
      restart_policy:
        condition: on-failure
    ports:
      - "8763:8763"
    networks:
      my-overlay-network:
        aliases:
          - eureka-server3
    depends_on:
      - eureka-server2
    environment:
        - "SPRING_PROFILES_ACTIVE=peer3-test"

networks:
  my-overlay-network:
    driver: overlay

你的项目配置里 image 我的是多环境的,你可以不和我的一样 peer1-test.yml

spring:
  profiles: peer1-test
  application:
    name: eureka-server
server:
  port: 8761

eureka:
  instance:
    hostname: eureka-server
#    prefer-ip-address: true
  client:
    register-with-eureka: false
    fetch-registry: false
    service-url:
       defaultZone: http://eureka-server2:8762/eureka/,http://eureka-server3:8763/eureka/

peer2-test.yml

spring:
  profiles: peer2-test
  application:
    name: eureka-server2
server:
  port: 8762

eureka:
  instance:
    hostname: eureka-server2
#    prefer-ip-address: true
  client:
    register-with-eureka: false
    fetch-registry: false
    service-url:
       defaultZone: http://eureka-server:8761/eureka/,http://eureka-server3:8763/eureka/

peer3-test.yml我就不粘了,你应该看的懂了 这样他们相互之间可以同步