Docker 搭建 Spring Cloud Eureka Server 集羣

擺置微服務,老是java -jar server.jar,顯得太low。docker助力下吧,不料倒騰良久。。。java

1、項目地址

2、注意事項

  • 主要是兩個配置文件:application.ymldocker-compose.yml
  • 集羣配置之簡化配置
    • defaultZone配置: http://slave1:8761/eureka/,http://slave2:8762/eureka/,http://slave3:8763/eureka/
    • docker-compose.yml配置:services 中的 server 名字要對應上邊的 slave1 / slave2 / slave3

application.yml

spring:
  application:
    name: mall-server

eureka:
  #  關閉自我保護模式
  #  eureka.server.enable-self-preservation: false
  client:
    healthcheck:
      enabled: true
    service-url:
      defaultZone: http://slave1:8761/eureka/,http://slave2:8762/eureka/,http://slave3:8763/eureka/

info:
  app:
    name: ${spring.application.name}
    description: Eureka 註冊中心
    version: 1.0.0

---
spring:
  profiles:
    slave1
server:
  port: 8761
eureka:
  instance:
    hostname: slave1

---
spring:
  profiles:
    slave2
server:
  port: 8762
eureka:
  instance:
    hostname: slave2

---
spring:
  profiles:
    slave3
server:
  port: 8763
eureka:
  instance:
    hostname: slave3

docker-compose.yml

version: '3.5'
services:
  slave1:
    container_name: s1
    image: mall/server:1.0.0
    networks:
      - mall-server-net
    ports:
      - 8761:8761
    environment:
      - SPRING_PROFILES_ACTIVE=slave1

  slave2:
    container_name: s2
    image: mall/server:1.0.0
    networks:
      - mall-server-net
    ports:
      - 8762:8762
    environment:
      - SPRING_PROFILES_ACTIVE=slave2

  slave3:
    container_name: s3
    image: mall/server:1.0.0
    networks:
      - mall-server-net
    ports:
      - 8763:8763
    environment:
      - SPRING_PROFILES_ACTIVE=slave3

networks:
  mall-server-net:
    name: mall-server-net
    driver: bridge
相關文章
相關標籤/搜索