天天看點

SpringCloud微服務雲架構建構B2B2C電子商務平台之-(十)高可用的服務注冊中心...

一、準備工作

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:

server:
  port: 8761
 
spring:
  profiles: peer1
eureka:
  instance:
    hostname: peer1
  client:
    serviceUrl:
      defaultZone: http://peer2:8769/eureka/複制代碼
           

并且建立另外一個配置檔案application-peer2.yml:

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 ,加上:

127.0.0.1 peer1
127.0.0.1 peer2複制代碼
           

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

這時需要改造下service-hi:

eureka:
  client:
    serviceUrl:
      defaultZone: http://peer1:8761/eureka/
server:
  port: 8762
spring:
  application:
    name: service-hi複制代碼
           

架構代碼如下:

資料和源碼來源位址

Spring Cloud大型企業分布式微服務雲建構的B2B2C電子商務平台源碼請加企鵝求求: 一零叁八七七四六貳

轉載于:https://juejin.im/post/5c2325e66fb9a049d9753f02