spring cloud互聯網分佈式微服務雲平臺-搭建高可用服務註冊中心

1、準備工做linux

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.spring

摘自官網vim

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

這篇文章咱們基於第一篇文章的工程,來作修改。願意瞭解源碼的朋友直接求求交流分享技術 一七九一七四三三八零bash

2、改造工做app

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

server:
  port: 8761

spring:
  profiles: peer1
eureka:
  instance:
    hostname: peer1
  client:
    serviceUrl:
      defaultZone: http://peer2:8769/eureka/
複製代碼

 而且建立另一個配置文件application-peer2.yml:url

server:
  port: 8769

spring:
  profiles: peer2
eureka:
  instance:
    hostname: peer2
  client:
    serviceUrl:
      defaultZone: http://peer1:8761/eureka/
複製代碼

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

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.code

按照官方文檔的指示,須要改變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
複製代碼
相關文章
相關標籤/搜索