在互联网应用中,服务实例很少有单个的。

  即使微服务消费者会缓存服务列表,但是如果EurekaServer只有一个实例,该实例挂掉,正好微服务消费者本地缓存列表中服务实例也不可用,那么这个时候整个系统都受影响。

  在⽣产环境中,我们会配置Eureka Server集群实现⾼可⽤。Eureka Server集群之中的节点通过点对点(P2P)通信的⽅式共享服务注册表。我们开启两台 Eureka Server 以搭建集群。

在本地模拟多个电脑步骤:

1.在host文件中的添加配置

SpringCloud之搭建Eureka Server HA⾼可⽤集群

 

2.在文件中添加2个服务的名称:FrankCloudEurekaServerB、FrankCloudEurekaServerA

 SpringCloud之搭建Eureka Server HA⾼可⽤集群

3.代码结构

SpringCloud之搭建Eureka Server HA⾼可⽤集群

4.2个服务端中的一个代码结构

SpringCloud之搭建Eureka Server HA⾼可⽤集群

 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
View Code

相关文章:

  • 2022-12-23
  • 2022-01-22
  • 2021-12-30
  • 2021-07-25
  • 2021-08-18
  • 2021-06-02
  • 2021-04-27
  • 2021-05-12
猜你喜欢
  • 2021-08-02
  • 2021-11-22
  • 2021-05-05
  • 2021-09-21
  • 2022-12-23
  • 2021-09-10
相关资源
相似解决方案