搭建Spring Cloud Eureka 三个节点高可用集群

(一)修改hosts文件:
搭建Spring Cloud Eureka 三个节点高可用集群_第1张图片

保证单节点可用的前提下

(二)Eureka server端配置文件:

spring:
  application:
    name: eureka-server
  profiles: discovery1
server:
  port: 8761
eureka:
  instance:
    hostname: discovery1
    lease-renewal-interval-in-seconds: 30
    lease-expiration-duration-in-seconds: 30
    prefer-ip-address: true
  client:
    serviceUrl:
      default-zone: http://discovery2:8762/eureka/, http://discovery3:8763/eureka/
    fetch-registry: true
    register-with-eureka: true

---
spring:
  application:
    name: eureka-server
  profiles: discovery2
server:
  port: 8762
eureka:
  instance:
    hostname: discovery2
    lease-renewal-interval-in-seconds: 30
    lease-expiration-duration-in-seconds: 30
    prefer-ip-address: true
  client:
    fetch-registry: true
    register-with-eureka: true
    serviceUrl:
      default-zone: http://discovery1:8761/eureka/, http://discovery3:8763/eureka/


---
spring:
  application:
    name: eureka-server
  profiles: discovery3
server:
  port: 8763
eureka:
  instance:
    lease-renewal-interval-in-seconds: 30
    lease-expiration-duration-in-seconds: 30
    hostname: discovery2
    prefer-ip-address: true
  client:
    fetch-registry: true
    register-with-eureka: true
    serviceUrl:
      default-zone: http://discovery1:8761/eureka/, http://discovery2:8762/eureka/

(三)启动配置

根据不同的环境启动实例

实例1:-Dspring.profiles.active=discovery1
实例2:-Dspring.profiles.active=discovery2
实例3:-Dspring.profiles.active=discovery3

(四)Eureka Client配置

eureka:
  client:
    service-url:
      default-zone: http://discovery1:8761/eureka/,http://discovery2:8762/eureka/,http://discovery3:8763/eureka/
#  instance:
#    hostname: discover
spring:
  application:
    name: client
server:
  port: 80

至此,三个节点的Eureka注册中心集群搭建完成,
注意事项:一定要修改hosts文件,不然集群不会生效。

你可能感兴趣的:(Spring,Cloud)