搭建eureka高可用

Eureka高可用

 

1.設置服務器之間的host,測試環境是在window10上搭建的,因此去修改C:\Windows\System32\drivers\etc文件,以下:git

 

image-20200427215406445

2.建立項目:spring

image-20200427215537059

image-20200427215912576

image-20200427220148974

image-20200427220546945

image-20200427220658909

3.編輯配置文件:服務器

 

application.yml:

  #一組服務須要使用相同的服務名稱,才能被識別爲一組!
  application:
    name: eureka-server

 

application-euk1.yml:

eureka:
  client:
    #集羣模式須要設置爲true
    register-with-eureka: true
    #集羣模式須要設置爲true
    fetch-registry: true
    #設置服務註冊中心的URL,用於client和server端交流
    #注意事項:
    #eureka.client.serviceUrl.defaultZone配置項的地址,不能使用localhost,要使用service-center-1之類的域名,經過host映射到127.0.0.1;
    service-url:
      defaultZone: http://euk2.com:8702/eureka/
  instance:
    #hostname爲必填
    hostname: euk1.com
server:
  port: 8701

 


application.euk2.yml:

eureka:
  client:
    register-with-eureka: true
    fetch-registry: true
    service-url:
      defaultZone: http://euk1.com:8701/eureka/
  instance:
    hostname: euk2.com
server:
  port: 8702

 

4.設置Configuration,以不一樣的配置文件啓動兩個eureka實例:app

image-20200427221214870

image-20200427221333002

image-20200427221743914

5.看一下啓動正常後的運行界面:(8702端口界面也是同樣的,就不貼了)測試

image-20200427222004793

6.總結:在部署eureka單節點和高可用時候遇到的坑:fetch

a.第一次部署eureka的時候,只是在配置文件中配置了eureka的相關配置,沒有在啓動類上加註解 @EnableEurekaServer,因此訪問控制檯報錯404url

b.一樣服務的client要起一樣的名稱(spring.application.name),否則eureka不會放在同一組裏面spa

相關文章
相關標籤/搜索