SpringCloud(三) eureka集群

Dear 丶 2022-05-23 03:36 292阅读 0赞

根据 SpringCloud(一) eureka服务注册与发现 ,再增加两个eureka server

Eureka Server的高可用

Eureka Server的设计一开始就考虑到了高可用的问题,在Eureka的服务治理设计中,所有节点即是服务提供方,也是服务消费方,服务注册也不列外。之前的有配置:
eureka:
client:
register-with-eureka: false
fetch-registry: false
让服务注册中心不注册自己。Eureka Server的高可用实际上就是将自己作为服务向其他服务注册中心注册自己,这样就可以形成一组互相注册的服务注册中心,以实现服务清单的互相同步,达到高可用的效果。

因为在一台机器上部署,修改hosts

  1. 127.0.0.1 localhost1
  2. 127.0.0.1 localhost2
  3. 127.0.0.1 localhost3

eureka-server1配置文件:

  1. server:
  2. port: 8761
  3. eureka:
  4. instance:
  5. hostname: localhost1
  6. client:
  7. register-with-eureka: true
  8. fetch-registry: true
  9. service-url:
  10. defaultZone: http://localhost2:8762/eureka,http://localhost3:8763/eureka
  11. spring:
  12. application:
  13. name: eureka-server1

eureka-server2配置文件:

  1. server:
  2. port: 8762
  3. eureka:
  4. instance:
  5. hostname: localhost2
  6. client:
  7. register-with-eureka: true
  8. fetch-registry: true
  9. service-url:
  10. defaultZone: http://localhost1:8761/eureka,http://localhost3:8763/eureka
  11. spring:
  12. application:
  13. name: eureka-server2

eureka-server3配置文件:

  1. server:
  2. port: 8763
  3. eureka:
  4. instance:
  5. hostname: localhost3
  6. client:
  7. register-with-eureka: true
  8. fetch-registry: true
  9. service-url:
  10. defaultZone: http://localhost1:8761/eureka,http://localhost2:8762/eureka
  11. spring:
  12. application:
  13. name: eureka-server3

eureka-client spring配置文件:

  1. server:
  2. port: 8080
  3. eureka:
  4. client:
  5. service-url:
  6. defaultZone: http://localhost1:8761/eureka,http://localhost2:8762/eureka,http://localhost3:8763/eureka
  7. spring:
  8. application:
  9. name: eureka-client1

先启动所有eureka,在启动客户端

访问:http://localhost:8761/ 或http://localhost:8762/ 或http://localhost:8763/

70

实时内容请关注微信公众号,公众号与博客同时更新:程序员星星

实时内容请关注微信公众号,公众号与博客同时更新

发表评论

表情:
评论列表 (有 0 条评论,292人围观)

还没有评论,来说两句吧...

相关阅读