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

itspring_cloud發表於2018-12-26

一、準備工作
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複製程式碼

架構程式碼如下:

"分散式b2b <wbr

資料和原始碼來源地址

Spring Cloud大型企業分散式微服務雲構建的B2B2C電子商務平臺原始碼請加企鵝求求: 一零叄八七七四六貳


相關文章