2-2、高可用服务注册中心

为了提高Eureka Server的可用性,我们可以通过运行多个实例,并进行互相注册的方式来实现高可用的部署。我们以运行3个Eureka Server为例,端口分别为:9100, 9200, 9300。

源码:高可用

2-2、高可用服务注册中心_第1张图片
服务集群.png

创建3个profile,如图:

2-2、高可用服务注册中心_第2张图片
配置文件.png

1、application.yml
spring:
  profiles:
    active: server1
2、application-server1.yml
server:
  port: 9100

spring:
  application:
    name: xx-server

eureka:
  instance:
    hostname: 127.0.0.1
  client:
    service-url:
      defaultZone: http://localhost:9100/eureka/,http://localhost:9200/eureka/,http://localhost:9300/eureka/
3、application-server2.yml
server:
  port: 9200

spring:
  application:
    name: xx-server

eureka:
  instance:
    hostname: 127.0.0.1
  client:
    service-url:
      defaultZone: http://localhost:9100/eureka/,http://localhost:9200/eureka/,http://localhost:9300/eureka/
4、application-server3.yml
server:
  port: 9300

spring:
  application:
    name: xx-server

eureka:
  instance:
    hostname: 127.0.0.1
  client:
    service-url:
      defaultZone: http://localhost:9100/eureka/,http://localhost:9200/eureka/,http://localhost:9300/eureka/
5、idea中启用时,指定3个不同的profile,参考下图:
2-2、高可用服务注册中心_第3张图片
idea启动项配置.png
6、启用3个实例,分别应对server1,server2,server3 这三个profile后,看下UI。
2-2、高可用服务注册中心_第4张图片
server1.png
2-2、高可用服务注册中心_第5张图片
server2.png
2-2、高可用服务注册中心_第6张图片
server3.png

####### 7、其它服务向eureka server集群注册时,参考下面的配置。

server:
    port: 8093

spring:
  application:
    name: rest-service

eureka:
  client:
    serviceUrl:
      defaultZone: http://localhost:9100/eureka/,http://localhost:9200/eureka/,http://localhost:9300/eureka/

你可能感兴趣的:(2-2、高可用服务注册中心)