在互联网应用中,服务实例很少有单个的。
即使微服务消费者会缓存服务列表,但是如果EurekaServer只有一个实例,该实例挂掉,正好微服务消费者本地缓存列表中服务实例也不可用,那么这个时候整个系统都受影响。
在⽣产环境中,我们会配置Eureka Server集群实现⾼可⽤。Eureka Server集群之中的节点通过点对点(P2P)通信的⽅式共享服务注册表。我们开启两台 Eureka Server 以搭建集群。
在本地模拟多个电脑步骤:
1.在host文件中的添加配置
2.在文件中添加2个服务的名称:FrankCloudEurekaServerB、FrankCloudEurekaServerA
3.代码结构
4.2个服务端中的一个代码结构
5.FrankCloudEurekaServerApplication8761 中的代码结构
1 package com.frank.edu; 2 3 import org.springframework.boot.SpringApplication; 4 import org.springframework.boot.autoconfigure.SpringBootApplication; 5 import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer; 6 7 @SpringBootApplication 8 @EnableEurekaServer 9 public class FrankCloudEurekaServerApplication8761 { 10 public static void main(String[] args) { 11 SpringApplication.run(FrankCloudEurekaServerApplication8761.class,args); 12 } 13 }
6.配置项application.yml
1 server: 2 port: 8761 3 spring: 4 application: 5 name: frank-cloud-eureka-server 6 7 eureka: 8 instance: 9 hostname: FrankCloudEurekaServerA 10 client: 11 fetch-registry: true 12 register-with-eureka: true 13 serviceUrl: 14 defaultZone: http://FrankCloudEurekaServerB:8762/eureka