溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

怎么使用Spring Cloud高可用的服務(wù)注冊中心

發(fā)布時間:2021-11-15 16:32:07 來源:億速云 閱讀:147 作者:iii 欄目:大數(shù)據(jù)

本篇內(nèi)容主要講解“怎么使用Spring Cloud高可用的服務(wù)注冊中心”,感興趣的朋友不妨來看看。本文介紹的方法操作簡單快捷,實用性強。下面就讓小編來帶大家學習“怎么使用Spring Cloud高可用的服務(wù)注冊中心”吧!

一、準備工作

繼續(xù)延用以前的項目,這里出現(xiàn)了點小插曲,由于打算不修改 hosts 文件去實現(xiàn)單臺服務(wù)器的服務(wù)集群,折騰一天也沒折騰明白,最后總結(jié)個結(jié)論:單臺服務(wù)器得修改hosts,多臺服務(wù)器可通過ip去配置。

修改 hosts  : C:\Windows\System32\drivers\etc

在文件最后添加幾行:

怎么使用Spring Cloud高可用的服務(wù)注冊中心

二、修改項目erurekaserver

1、新建application-one.yml

server:
  port: 8761
spring:
  application:
    name: eurekaserver
  profiles: one
eureka:
  instance:
    hostname: localhost1
  client:
    register-with-eureka: true
    fetch-registry: true
    serviceUrl:
      defaultZone: http://localhost2:8861/eureka/
  server:
    enableSelfPreservation: false

2、新建application-two.yml

server:
  port: 8861
spring:
  application:
    name: eurekaserver
  profiles: two

eureka:
  instance:
    hostname: localhost2
  client:
    register-with-eureka: true
    fetch-registry: true
    serviceUrl:
      defaultZone: http://localhost1:8761/eureka/
  server:
    enableSelfPreservation: false

3、修改啟動項

EurekaServerApplication.java 右鍵 -> Run As -> Run Configruations.. 創(chuàng)建兩個啟動應(yīng)用

怎么使用Spring Cloud高可用的服務(wù)注冊中心

怎么使用Spring Cloud高可用的服務(wù)注冊中心

4、分別啟動 one  two

啟動的時候總是有個后臺會報錯,等啟動完成后就好了。分別訪問:http://localhost:8761/,http://localhost:8861/,結(jié)果如下:

怎么使用Spring Cloud高可用的服務(wù)注冊中心怎么使用Spring Cloud高可用的服務(wù)注冊中心

三、修改config-server項目

1、修改application.properties,紅框標注部分

怎么使用Spring Cloud高可用的服務(wù)注冊中心

2、啟動config-server

四、修改eurekaclient1的bootstrap.yml

怎么使用Spring Cloud高可用的服務(wù)注冊中心

啟動項目

五、修改service-ribbon的 application.yml

怎么使用Spring Cloud高可用的服務(wù)注冊中心

啟動項目

六、再次分別訪問:http://localhost:8761/,http://localhost:8861/

怎么使用Spring Cloud高可用的服務(wù)注冊中心

怎么使用Spring Cloud高可用的服務(wù)注冊中心

七、訪問http://localhost:8764/hello

怎么使用Spring Cloud高可用的服務(wù)注冊中心

可成功訪問。

到此,相信大家對“怎么使用Spring Cloud高可用的服務(wù)注冊中心”有了更深的了解,不妨來實際操作一番吧!這里是億速云網(wǎng)站,更多相關(guān)內(nèi)容可以進入相關(guān)頻道進行查詢,關(guān)注我們,繼續(xù)學習!

向AI問一下細節(jié)

免責聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI