您好,登錄后才能下訂單哦!
本篇內(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
在文件最后添加幾行:
二、修改項目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)用
4、分別啟動 one two
啟動的時候總是有個后臺會報錯,等啟動完成后就好了。分別訪問:http://localhost:8761/,http://localhost:8861/,結(jié)果如下:
三、修改config-server項目
1、修改application.properties,紅框標注部分
2、啟動config-server
四、修改eurekaclient1的bootstrap.yml
啟動項目
五、修改service-ribbon的 application.yml
啟動項目
六、再次分別訪問:http://localhost:8761/,http://localhost:8861/
七、訪問http://localhost:8764/hello
可成功訪問。
到此,相信大家對“怎么使用Spring Cloud高可用的服務(wù)注冊中心”有了更深的了解,不妨來實際操作一番吧!這里是億速云網(wǎng)站,更多相關(guān)內(nèi)容可以進入相關(guān)頻道進行查詢,關(guān)注我們,繼續(xù)學習!
免責聲明:本站發(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)容。