java B2B2C Springcloud多租戶電子商城系統-高可用的服務註冊中心

小兵2147775633發表於2019-01-30

一、準備工作 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.

摘自官網

需要JAVA Spring Cloud大型企業分散式微服務雲構建的B2B2C電子商務平臺原始碼 一零三八七七四六二六

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
複製程式碼

java B2B2C Springcloud多租戶電子商城系統

相關文章