1000字范文,内容丰富有趣,学习的好帮手!
1000字范文 > JavaEE 企业级分布式高级架构师(十三)微服务框架 SpringCloud (H 版)(1)

JavaEE 企业级分布式高级架构师(十三)微服务框架 SpringCloud (H 版)(1)

时间:2020-10-20 12:39:27

相关推荐

JavaEE 企业级分布式高级架构师(十三)微服务框架 SpringCloud (H 版)(1)

Spring Cloud学习笔记

Spring Cloud入门分布式技术图谱Spring Cloud简介官网介绍百度百科总结Spring Cloud的国内使用情况Spring Cloud在线资源Spring Cloud版本版本号来源Spring Cloud与Spring Boot版本Spring Cloud与Dubbo技术选型SpringCloud演示项目框架搭建创建公共模块 00-common创建提供者工程 01-provider-8090创建消费者工程 01-consumer-8080微服务注册中心EurekaEureka概述Eureka简介Eureka体系架构CAP定理概念定理Eureka与Zookeeper对比Eureka的闭源谣言搭建Eureka服务中心创建eureka工程 00-eureka-server-8000搭建Eureka的客户端服务创建提供者工程 02-provider-8090创建消费者工程 02-consumer-8080Eureka进阶服务发现Discovery自我保护机制EurekaServer集群服务下架关闭服务服务平滑上下线Eureka 的异地多活Region 与 ZoneEureka 中的Region与Zone配置

Spring Cloud入门

分布式技术图谱

Spring Cloud简介

官网介绍

打开 Spring 官网 http://spring.io 首页的中部,可以看到 Spring Cloud 的简介。【原文】Building distributed systems doesn’t need to be complex and error-prone(易错). Spring Cloud offers a simple and accessible(易接受的) programming model to the most common distributed system patterns(模式), helping developers build resilient(有弹性的), reliable(可靠的), and coordinated(协调的) applications. Spring Cloud is built on top of Spring Boot, making it easy for developers to get started and become productive quickly.【翻译】构建分布式系统不需要复杂和容易出错。Spring Cloud 为最常见的分布式系统模式提供了一种简单且易于接受的编程模型,帮助开发人员构建有弹性的、可靠的、协调的应用程序。Spring Cloud 构建于 Spring Boot 之上,使得开发者很容易入手并快速应用于生产中。

百度百科

Spring Cloud 是一系列框架的有序集合。它利用 Spring Boot 的开发便利性巧妙地简化了分布式系统基础设施的开发,如服务发现注册、配置中心、消息总线、负载均衡、断路器、数据监控等,都可以用 Spring Boot 的开发风格做到一键启动和部署。Spring Cloud 并没有重复制造轮子,它只是将目前各家公司开发的比较成熟、经得起实际考验的服务框架组合起来,通过 Spring Boot 风格进行再封装屏蔽掉了复杂的配置和实现原理,最终给开发者提供了一套简单易懂、易部署和易维护的分布式系统开发工具包。

总结

Spring Cloud 是什么?

阿里高级框架师、Dubbo 项目的负责人刘军说,Spring Cloud 是微服务系统架构的一站式解决方案。

Spring Cloud 与 Spring Boot 是什么关系呢?

Spring Boot 为 Spring Cloud 提供了代码实现环境,使用 Spring Boot 将其它组件有机融合到了 Spring Cloud 的体系架构中了。所以说,Spring Cloud 是基于 Spring Boot 的、微服务系统架构的一站式解决方案。

Spring Cloud的国内使用情况

在 Spring Cloud 中国社区博客中可以看到 Spring Cloud 在国内的使用情况。/about/

Spring Cloud在线资源

Spring Cloud官网:https://projects.spring.io/spring-cloud/Spring Cloud中文网:/Spring Cloud中国社区:/

Spring Cloud版本

版本号来源

Spring Cloud 的版本号并不是我们通常见的数字版本号,而是一些很奇怪的单词。这些单词均为英国伦敦地铁站的站名。同时根据字母表的顺序来对应版本时间顺序,比如:最早的 Release 版本 Angel(天使),第二个 Release 版本 Brixton(英国地名),然后是 Camden、Dalston、Edgware,目前使用较多的是 Finchley(英国地名)版本,而最新版本为 Hoxton(英国地名),而我们这里要使用的是 Greenwich(格林威治)。国内为了沟通的简单,我们一般称 Finchley 版本为 F 版本,Greenwich 版本为 G 版等。Spring Cloud 的一个大版本在不同的阶段会发布不同类型的小版本号。按照发行的顺序,一般会存在这些版本,但并不一定每个大版本都存在这些小版本。当然,这些小版本后一般还会添加上数字作为其内部的版本。PRE:preview,预览版,内测版。SNAPSHOT:快照版。M版:Milestone,里程碑版。RC版:Release Candidate,发行候选版本。SR版:Service Release,服务发布版,正式发行版。GA版:General Availability,则表示这是当前广泛使用的版本。CURRENT:表示官方当前推荐版本。

Spring Cloud与Spring Boot版本

某一版本的 Spring Cloud 要求必须要运行在某一特定 Spring Boot 版本下。它们的对应关系在 Spring Cloud 官网首页最下面可以看到版本对应说明。

Spring Cloud与Dubbo技术选型

Spring Cloud 与 Dubbo 均为微服务框架,开发团队在进行技术选型时,总会将它们进行对比,考虑应该选择哪一个。可以从以下几方面考虑:

架构完整度:Dubbo仅提供了服务注册与服务治理两个模块,需要其他功能,需求进行整合;Spring Cloud更加完整社区活跃度:Spring Cloud全世界都在用,资料很多是英语;Dubbo主要是国内在用,且资料都是中文。通讯协议:Dubbo是RPC框架,底层使用Netty,RPC 对业务接口具有强依赖性;Spring Cloud——HTTP REST,Spring Cloud gRPC。Spring Cloud Dubbo方向。技术改造与微服务开发:Dubbo适合做技术改造,新的微服务开发一般选 Spring Cloud。

SpringCloud演示项目框架搭建

源码github地址:/shouwangyw/springcloud项目工程名:springcloud-example-parent使用的 Spring Cloud 版本为 Hoxton.SR1,主要依赖:

<modelVersion>4.0.0</modelVersion><parent><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-parent</artifactId><version>2.2.2.RELEASE</version><relativePath/></parent><groupId>com.yw.springcloud.example</groupId><artifactId>springcloud-example-parent</artifactId><version>1.0</version><packaging>pom</packaging><properties><java.version>1.8</java.version><spring-cloud.version>Hoxton.SR1</spring-cloud.version></properties><dependencyManagement><dependencies><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-dependencies</artifactId><version>${spring-cloud.version}</version><type>pom</type><scope>import</scope></dependency><!-- MySQL驱动版本 --><dependency><groupId>mysql</groupId><artifactId>mysql-connector-java</artifactId><version>5.1.47</version></dependency><!-- 数据源 --><dependency><groupId>com.alibaba</groupId><artifactId>druid</artifactId><version>1.1.10</version></dependency></dependencies></dependencyManagement><dependencies><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-test</artifactId><scope>test</scope></dependency><dependency><groupId>org.projectlombok</groupId><artifactId>lombok</artifactId></dependency></dependencies>

创建公共模块 00-common

依赖:使用 Spring Data JPA 作为持久层技术

<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-data-jpa</artifactId></dependency>

分别创建实体类、repository接口和service接口:

@Data@Accessors(chain = true)@Entity@JsonIgnoreProperties({"hibernateLazyInitializer", "handler", "fieldHandler"})// JPA的默认实现是hibernate,而 hibernate 默认对于对象的查询是基于延迟加载的// 例如 Depart depart = service.findById(5); 这里的depart实际是一个javasist冬天代理对象// 只有当真正使用到depart里面的属性时,才会真正的执行查询public class Depart {/*** @Id 表示当前属性映射到表中为主键* @GeneratedValue 主键是自动递增的*/@Id@GeneratedValue(strategy = GenerationType.IDENTITY)private Integer id;private String name;}/*** JpaRepository<Depart, Integer>*第一个泛型:当前Repository的操作对象类型*第二个泛型:当前Repository的操作对象的id类型*/public interface DepartRepository extends JpaRepository<Depart, Integer> {}public interface DepartService {boolean saveOne(Depart depart);boolean deleteById(int id);boolean updateOne(Depart depart);Depart getDepartById(int id);List<Depart> listDeparts();}

创建提供者工程 01-provider-8090

该工程是一个单纯的 Spring Boot 工程,还并未使用到 Spring Cloud,但其为后续 Spring Cloud 的运行测试环境。依赖:00-common公共模块、MySQL驱动和druid连接池

<dependency><groupId>com.yw.springcloud.example</groupId><artifactId>00-common</artifactId><version>1.0</version></dependency><!-- MySQL驱动版本 --><dependency><groupId>mysql</groupId><artifactId>mysql-connector-java</artifactId><scope>runtime</scope></dependency><!-- 数据源 --><dependency><groupId>com.alibaba</groupId><artifactId>druid</artifactId></dependency>

application.yml 配置:

server:port: 8090# 设置Spring-Data-JPAspring:jpa:# 指定在Spring容器启动时是否自动建表,默认为falsegenerate-ddl: true# 指定是否在控制台显示其执行的SQL语句,默认falseshow-sql: true# 指定应用重启时是否重新创建更新表hibernate:ddl-auto: nonedatasource:type: com.alibaba.druid.pool.DruidDataSourcedriver-class-name: com.mysql.jdbc.Driverurl: jdbc:mysql://192.168.254.128:3306/test?useUnicode=true&amp;characterEncoding=utf8username: rootpassword: 123456logging:# 设置日志输出格式pattern:console: level-%level %msg%nlevel:# 控制Spring Boot启动时的日志级别root: info# 控制hibernate运行时的日志级别org.hibernate: info# 在show-sql为true时,显示SQL中的动态参数值org.hibernate.type.descriptor.sql.BasicBinder: trace# 在show-sql为true时,显示SQL查询结果org.hibernate.type.descriptor.sql.BasicExtractor: tracecom.yw.provider: debug

创建业务接口实现类和 Controller 层的接口实现:

@Servicepublic class DepartServiceImpl implements DepartService {@Autowiredprivate DepartRepository repository;@Overridepublic boolean saveOne(Depart depart) {// repository.save()可以完成插入和修改// 若操作对象的id==null,则执行插入;若id!=null,则执行修改;// 若操作对象的id!=null但不存在,则执行插入,但插入后该对象id并非是指定的id,而是由DB自动生成return repository.save(depart) != null;}@Overridepublic boolean deleteById(int id) {// repository.existsById()中指定的id若不存在,则会抛出异常,因此这里要先判断是否存在if (repository.existsById(id)) {repository.deleteById(id);return true;}return false;}@Overridepublic boolean updateOne(Depart depart) {return repository.save(depart) != null;}@Overridepublic Depart getDepartById(int id) {// repository.getOne()中指定的id若不存在,则会抛出异常,因此这里要先判断是否存在if (repository.existsById(id)) {return repository.getOne(id);}return new Depart().setName("No this depart");}@Overridepublic List<Depart> listDeparts() {return repository.findAll();}}

@RestController@RequestMapping("/provider/depart")public class DepartController {@Autowiredprivate DepartService departService;@PostMapping("/save")public boolean saveHandle(@RequestBody Depart depart) {return departService.saveOne(depart);}@DeleteMapping("/del/{id}")public boolean deleteHandle(@PathVariable("id") int id) {return departService.deleteById(id);}@PutMapping("/update")public boolean updateHandle(@RequestBody Depart depart) {return departService.updateOne(depart);}@GetMapping("/get/{id}")public Depart getHandle(@PathVariable("id") int id) {return departService.getDepartById(id);}@GetMapping("/list")public List<Depart> listHandle() {return departService.listDeparts();}}

启动项目,通过Postman进行接口测试,或者谷歌浏览器的 Restlet Client 插件进行测试。使用JPA,在项目启动时会自动创建数据库。由于还没有接入注册中心这些,启动时会有一些报错信息,但是不影响。能正常进行CURD接口操作,说明项目跑通啦!!下面就开始搭建消费者工程。

创建消费者工程 01-consumer-8080

复制 01-provider-8090 工程,并重命名为 01-consumer-8080,删掉数据库驱动和连接池的依赖,yml配置文件也删掉,使用默认8080端口,修改启动类和 Controller 层接口:

@SpringBootApplication(exclude = DataSourceAutoConfiguration.class)public class ConsumerApplication {public static void main(String[] args) {SpringApplication.run(ConsumerApplication.class, args);}@Beanpublic RestTemplate restTemplate(){return new RestTemplate();}}

@RestController@RequestMapping("/consumer/depart")public class DepartController {private final static String API_URL = "http://localhost:8090/provider/depart/";@Autowiredprivate RestTemplate restTemplate;@PostMapping("/save")public boolean saveHandle(@RequestBody Depart depart) {return restTemplate.postForObject(API_URL + "save", depart, Boolean.class);}@DeleteMapping("/del/{id}")public void deleteHandle(@PathVariable("id") int id) {restTemplate.delete(API_URL + "del/" + id);}@PutMapping("/update")public void updateHandle(@RequestBody Depart depart) {restTemplate.put(API_URL + "update", depart);}@GetMapping("/get/{id}")public Depart getHandle(@PathVariable("id") int id) {return restTemplate.getForObject(API_URL + "get/" + id, Depart.class);}@GetMapping("/list")public List<Depart> listHandle() {return restTemplate.getForObject(API_URL + "list", List.class);}}

启动消费者工程,然后,通过Postman进行测试,或者谷歌浏览器的 Restlet Client 插件进行测试。 至此,我们就搭建完成了最简单的 服务提供者与服务消费者 的框架模型,主要使用 RestTemplate 进行远程调用。

微服务注册中心Eureka

Eureka概述

Eureka简介

Eureka,古希腊词语,英文读音[juə’ri:kə],意思是“我找到了!我发现了!”Eureka 是 Netflix 开发的服务发现框架,本身是一个基于 REST 的服务,主要用于定位运行在 AWS 域中的中间层服务,以达到负载均衡和中间层服务故障转移的目的。SpringCloud 将它集成在其子项目 spring-cloud-netflix 中,实现 SpringCloud 的服务发现功能。其实,Eureka 就是一个专门用于服务发现的服务器,一些服务注册到该服务器,而另一些服务通过该服务器查找其所要调用执行的服务。可以充当服务发现服务器的组件很多,例如 Zookeeper、Consul、Eureka 等。

Eureka体系架构

High level architecture:/Netflix/eureka/wiki/Eureka-at-a-glance

CAP定理

概念

CAP 定理指的是在一个分布式系统中,Consistency(一致性)、 Availability(可用性)、Partition tolerance(分区容错性),三者不可兼得。

一致性(C):分布式系统中多个主机之间是否能够保持数据一致的特性。即,当系统数据发生更新操作后,各个主机中的数据仍然处于一致的状态。可用性(A):系统提供的服务必须一直处于可用的状态,即对于用户的每一个请求,系统总是可以在有限的时间内对用户做出响应。分区容错性(P):分布式系统在遇到任何网络分区故障时,仍能够保证对外提供满足一致性和可用性的服务。

定理

CAP 定理的内容是:对于分布式系统,网络环境相对是不可控的,出现网络分区是不可避免的,因此系统必须具备分区容错性。但系统不能同时保证一致性与可用性。即要么 CP,要么 AP。

Eureka与Zookeeper对比

Eureka 与 Zookeeper 都可以充当服务中心,那么它们有什么区别呢?它们的区别主要体现在对于 CAP 原则的支持的不同。 Eureka:AP原则Zookeeper:CP原则

Eureka的闭源谣言

Eureka 官网的 wiki 中公布了如下内容: 【原文】The existing open source work on eureka 2.0 is discontinued(终止). The code base(代码库) and artifacts(工程) that were released as part of the existing repository of work on the 2.x branch is considered use at your own risk(被认为在自己的风险中使用).

Eureka 1.x is a core part of Netflix’s service discovery system and is still an active project. Additionally(另外), extension work(扩展工作) on eureka 1.x has moved(推进) internally 内部) within Netflix.【翻译】现在的关于 eureka 2.0 的开源工作已经终止。已经发布的现存库中的关于 2.x 分支部分的代码库与工程,你的使用将自负风险。 Erueka 1.x 是 Netflix 服务发现系统的核心部分,其仍是一个活跃项目。另外,在 Eureka 1.x 上的扩展工作已经在 Netflix 内部推进。

搭建Eureka服务中心

创建eureka工程 00-eureka-server-8000

依赖:这里创建一个普通的 Spring Boot 工程,命名为 00-eureka-server-8000,仅导入 Eureka Server 依赖即可。

<!-- eureka server的依赖 --><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-netflix-eureka-server</artifactId></dependency>

application.yml 配置文件:

server:port: 8000eureka:instance:# 指定Eureka主机hostname: localhostclient:# 指定当前主机是否需要向注册中心注册?# 不用,因为当前主机是Server,不是Clientregister-with-eureka: false# 指定当前主机是否需要获取注册信息?不用。。。fetch-registry: false# 暴露服务中心地址service-url:#defaultZone: http://localhost:8000/eurekadefaultZone: http://${eureka.instance.hostname}:${server.port}/eureka

启动类开启Eureka服务:

@SpringBootApplication@EnableEurekaServer// 开启Eureka服务public class EurekaServerApplication {public static void main(String[] args) {SpringApplication.run(EurekaServerApplication.class, args);}}

用浏览器访问http://localhost:8000/出来了Eureka 的管理界面。

搭建Eureka的客户端服务

创建提供者工程 02-provider-8090

复制 01-provider-8090 工程,并重命名为 02-provider-8090,添加 eureka 客户端依赖

<!--eureka客户端依赖--><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-netflix-eureka-client</artifactId></dependency>

修改yml配置文件: 微服务健康检查:在提供者工程的 pom 中添加 actuator 监控依赖。

<!--actuator依赖--><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-actuator</artifactId></dependency>

yml配置文件添加如下内容:

info:company.name: company.addr: China Shenzhencompany.tel: 12345678app.name: yw-mscapp.desc: mic-server-cloudauthor: yw

启动项目,并访问 eureka 注册中心http://localhost:8000/,和健康检查地址http://localhost:8090/actuator/info

创建消费者工程 02-consumer-8080

复制 012-consumer-8080 工程,并重命名为 02-consumer-8080,与 02-provider-8090 工程一样需要添加 eureka 客户端依赖和 actuator 健康检查依赖。修改 application.yml 配置文件:

spring:# 指定当前微服务对外暴露的名称application:name: msc-consumer-departeureka:# 指定eureka服务中心client:service-url:defaultZone: http://localhost:8000/eureka

修改 Controller 接口处理:消费者将使用提供者暴露的服务名称(spring.application.name)来消费服务 修改启动类:不需要显示开启服务发现(若是纯SpringBoot工程则需要开启),开启消费者客户端的负载均衡功能 启动消费者工程,进行接口测试,结果显示可以通过提供者暴露的服务名称进行正常的消费。这样我们就利用eureka注册中心实现了通过提供者微服务名进行服务的调用功能。

Eureka进阶

服务发现Discovery

在 02-provider-8090 中新增一个接口方法:

// 声明服务发现客户端@Autowiredprivate DiscoveryClient client;@GetMapping("/discovery")public Object discoveryHandle() {// 获取Eureka中所有的微服务名称List<String> serviceNames = client.getServices();// 遍历for (String name : serviceNames) {// 根据微服务名称获取所有提供该服务的主机信息List<ServiceInstance> instances = client.getInstances(name);for (ServiceInstance instance : instances) {System.out.println(instance.getHost() + " : " + instance.getPort());}}return serviceNames;}

测试访问地址:http://localhost:8090/provider/depart/discovery

自我保护机制

刷新 Eureka 服务页面,可以看到如下红色字体内容,表示当前 EurekaServer 启动了自我保护机制,进入了自我保护模式。 【原文】Emergency (紧急情况) ! Eureka may be incorrectly claiming(判断) instances(指微服务主机) are up when they’re not. Renewals(续约,指收到的微服务主机的心跳) are lesser than threshold(阈值) and hence(从此) the instances are not being expired(失效) just to be(只是为了) safe.【翻译】紧急情况!当微服务主机联系不上时,Eureka 不能够正确判断它们是否处于 up 状态。当更新(指收到的微服务主机的心跳)小于阈值时,为了安全,微服务主机将不再失效。默认情况下,EurekaServer 在 90 秒内没有检测到服务列表中的某微服务,则会自动将该微服务从服务列表中删除。但很多情况下并不是该微服务节点(主机)出了问题,而是由于网络抖动等原因使该微服务无法被EurekaServer发现,即无法检测到该微服务主机的心跳。若在短暂时间内网络恢复正常,但由于 EurekaServer 的服务列表中已经没有该微服务,所以该微服务已经无法提供服务了。在短时间内若 EurekaServer 丢失较多微服务(EurekaServer 收到的心跳数量小于阈值),那么其会自动进入自我保护模式:服务列表只可读取、写入,不可执行删除操作。当 EurekaServer 收到的心跳数量恢复到阈值以上时,其会自动退出 Self Preservation 模式(翻译自官网)。 默认值修改 启动自我保护的阈值因子默认为 0.85,即 85%。即 EurekaServer 收到的心跳数量若小于应该收到数量的 85%时,会启动自我保护机制。自我保护机制默认是开启的,可以通过修改 EurekaServer 中配置文件来关闭。但不建议关闭。Renews threshold:Eureka Server 期望每分钟收到客户端的续约总数Renews (last min):Eureka Server 实际在最后一分钟收到客户端的续约数量 若 Renews (last min) 小于 Renews threshold,就会启动自我保护

EurekaServer集群

这里在本地启动三个Eureka Server节点,端口号分别为 8100、8200 与 8300,IDEA允许并行运行,通过修改配置开启三个Eureka Server。 任意访问其中一台Eureka:http://localhost:8100/ Eureka Client 端需要修改注册中心地址:

服务下架

Eureka Client 需要添加 actuator 健康检查依赖。

关闭服务

在 application.yml 配置文件中添加:

management:# 开启所有监控终端endpoints:web:exposure:include: "*"# 开启shutdown监控终端endpoint:shutdown:enabled: true

在 postman 提交如下请求即可关闭该应用

服务平滑上下线

前面的“关闭服务”方式存在一个不足是,若还需要再启用该服务,则必须再次启动该应用。我们也可以通过修改服务的状态为 UP 或 DOWN 来设置提供者是否可用,而无需重启应用。这种方式通常称为服务的平滑上下线。在 application.yml 配置文件中修改:

management:# 开启所有监控终端endpoints:web:exposure:include: "*"

在 postman 提交如下请求即可下线该应用 如果想再次上线服务,就可以提交如下请求

Eureka 的异地多活

Region 与 Zone

Eureka 中具有 Region 与 Availability Zone(简称AZ)概念,是云计算中的概念。为了方便不同地理区域中用户的使用,大型云服务提供商一般会根据用户需求量再不同城市、省份、国家或洲创建不同的大型云计算机房。这些不同区域机房间一般是不能“内网连通”的,这些区域就称为一个Region。这里存在一个问题:同一个 Region 机房是如何实现同域容灾的?为了增强容灾能力,在一个 Region 中又设置了不同的 Availability Zone。这些AZ 间实现了内网连通,且用户可以根据自己所在的具体位置选择同域中的不同 AZ。当用户所要访问的 AZ 出现问题后,系统会自动切换到其它可用的 AZ。例如, AWS 将全球划分为了很多的 Region,例如:美国东部区、美国西部区、欧洲区、非洲开普敦区、亚太区等。像 Eureka 系统架构图中的 us-east-1c、us-east-1d、us-east-1e 就是 us-east-1 这个 Region 中的 c、d、e 三个 AZ。再比如,阿里云在我国境内的 Region 有杭州、北京、深圳、青岛、香港等,境外 Region 有亚太东南 1 区(新加坡)、亚太东南 2 区(悉尼)、亚太东北 1 区(东京)。region 与 zone 的关系是 1:n;zone与Eureka的关系是 1:n。

eureka:client:region: xxxavailability-zones: xxx: k1, k2service-url:k1: http://xxxxxxx:8000/eurekak2: http://yyyyyyy:8000/eureka

Eureka 中的Region与Zone配置

需求:假设某公司的服务器有 Beijing、Shanghai 等多个 Region。Beijing 这个 Region 中存在两个 AZ,分别是 bj-1 与 bj-2,每个 AZ 中有三台 Eureka Server。h-1 与 h-2 两台主机提供的都是相同的 Servivce 服务,根据地理位置的不同,这两台主机分别注册到了距离自己最近的不同 AZ 的 Eureka Server。Server AZ bj-1、 Server AZ bj-2 配置,以及 Service AZ bj-1、 Service AZ bj-2 : Zuul AZ bj-1 和 Zuul AZ bj-2 配置:

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。