1. 程式人生 > >企業分布式微服務雲SpringCloud SpringBoot mybatis (十)高可用的服務註冊中心

企業分布式微服務雲SpringCloud SpringBoot mybatis (十)高可用的服務註冊中心

containe ans window profile 史上最簡單 avi 多個實例 可用 ren

文章 史上最簡單的 SpringCloud 教程 | 第一篇: 服務的註冊與發現(Eureka) 介紹了服務註冊與發現,其中服務註冊中心Eureka Server,是一個實例,當成千上萬個服務向它註冊的時候,它的負載是非常高的,這在生產環境上是不太合適的,這篇文章主要介紹怎麽將Eureka Server集群化。

一、準備工作

Eureka can be made even more resilient and available by running multiple instances and asking them to register with each other. In fact, this is the default behaviour, so all you need to do to make it work is add a valid serviceUrl to a peer, e.g.

摘自官網

Eureka通過運行多個實例,使其更具有高可用性。事實上,這是它默認的熟性,你需要做的就是給對等的實例一個合法的關聯serviceurl。

這篇文章我們基於第一篇文章的工程,來做修改。

二、改造工作

在eureka-server工程中resources文件夾下,創建配置文件application-peer1.yml:

1 2 3 4 5 6 7 8 9 10 11 server: port: 8761 spring: profiles: peer1 eureka: instance:
hostname: peer1 client: serviceUrl: defaultZone: http://peer2:8769/eureka/

  並且創建另外一個配置文件application-peer2.yml:

1 2 3 4 5 6 7 8 9 10 11 server: port: 8769 spring: profiles: peer2 eureka: instance: hostname: peer2 client:
serviceUrl: defaultZone: http://peer1:8761/eureka/

  這時eureka-server就已經改造完畢。

ou could use this configuration to test the peer awareness on a single host (there’s not much value in doing that in production) by manipulating /etc/hosts to resolve the host names.

按照官方文檔的指示,需要改變etc/hosts,linux系統通過vim /etc/hosts ,加上:

1 2 127.0.0.1 peer1 127.0.0.1 peer2

  

windows電腦,在c:/windows/systems/drivers/etc/hosts 修改。

這時需要改造下service-hi:

1 2 3 4 5 6 7 8 9 eureka: client: serviceUrl: defaultZone: http://peer1:8761/eureka/ server: port: 8762 spring: application: name: service-hi

  架構代碼如下:

技術分享圖片

Spring Cloud大型企業分布式微服務雲架構源碼請加企鵝求求:一七九一七四三三八零

企業分布式微服務雲SpringCloud SpringBoot mybatis (十)高可用的服務註冊中心