Eureka高可用搭建

1.高可用原理

每一台Eureka只需要在配置中指定另外多个Eureka的地址就可以实现一个集群的搭建了。

举例:

假设我们有master和slaveone两台机器,需要做的就是:

  • 将master注册到slaveone上面。
  • 将slaveone注册到master上面。

如果是3台机器,以此类推:

  • 将master注册到slaveone和slavetwo上面。
  • 将slaveone注册到master和slavetwo上面。
  • 将slavetwo注册到master和slaveone上面。

2.搭建步骤

配置与eureka注册中心-简版搭建一样,不同之处在于增加了多个不同环境的application.yml。

添加application-master.yml:

server:
  port=8761
  
# 指向从节点的Eureka
eureka:
  client:
    serviceUrl:
      defaultZone: http://username:password@localhost:8762/eureka/

添加application-slaveone.yml:

server:
  port=8762
  
# 指向从节点的Eureka
eureka:
  client:
    serviceUrl:
      defaultZone: http://username:password@localhost:8761/eureka/

需要部署到多少台机器上,就添加多少个配置文件

在application.yml中添加如下配置:

spring:
  profiles
    active: master

部署成功后,启动时需添加参数:

--spring.profiles.active= slaveone

3.注意

当注册中心有多个节点时,需要修改eureka.client.serviceUrl.defaultZone的配置为多个节点的地址,多个地址用英文逗号隔开:

eureka:
  client:
    serviceUrl:
      defaultZone: http://username:password@localhost:8761/eureka/,http://username:password@localhost:8762/eureka/

猜你喜欢

转载自www.cnblogs.com/gxloong/p/12364620.html