這篇文章主要介紹了Spring Cloud如何實現(xiàn)高可用的服務(wù)注冊中心,具有一定借鑒價值,感興趣的朋友可以參考下,希望大家閱讀完這篇文章之后大有收獲,下面讓小編帶著大家一起了解一下。
成都創(chuàng)新互聯(lián)公司網(wǎng)站建設(shè)由有經(jīng)驗的網(wǎng)站設(shè)計師、開發(fā)人員和項目經(jīng)理組成的專業(yè)建站團隊,負(fù)責(zé)網(wǎng)站視覺設(shè)計、用戶體驗優(yōu)化、交互設(shè)計和前端開發(fā)等方面的工作,以確保網(wǎng)站外觀精美、成都網(wǎng)站設(shè)計、做網(wǎng)站易于使用并且具有良好的響應(yīng)性。
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.
摘自官網(wǎng)
Eureka通過運行多個實例,使其更具有高可用性。事實上,這是它默認(rèn)的熟性,你需要做的就是給對等的實例一個合法的關(guān)聯(lián)serviceurl。
這篇文章我們基于第一篇文章的工程,來做修改。
在eureka-server工程中resources文件夾下,創(chuàng)建配置文件application-peer1.yml:
server: port: 8761 spring: profiles: peer1 eureka: instance: hostname: peer1 client: serviceUrl: defaultZone: http://peer2:8769/eureka/
并且創(chuàng)建另外一個配置文件application-peer2.yml:
server: port: 8769 spring: profiles: peer2 eureka: instance: hostname: peer2 client: serviceUrl: defaultZone: http://peer1:8761/eureka/
這時eureka-server就已經(jīng)改造完畢。
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系統(tǒng)通過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
啟動eureka-server:
java -jar eureka-server-0.0.1-SNAPSHOT.jar - -spring.profiles.active=peer1
java -jar eureka-server-0.0.1-SNAPSHOT.jar - -spring.profiles.active=peer2
>
啟動service-hi:
java -jar service-hi-0.0.1-SNAPSHOT.jar
訪問:localhost:8761,如圖:
你會發(fā)現(xiàn)注冊了service-hi,并且有個peer2節(jié)點,同理訪問localhost:8769你會發(fā)現(xiàn)有個peer1節(jié)點。
client只向8761注冊,但是你打開8769,你也會發(fā)現(xiàn),8769也有 client的注冊信息。
個人感受:這是通過看官方文檔的寫的demo ,但是需要手動改host是不是不符合Spring Cloud 的高上大?
Prefer IP Address
In some cases, it is preferable for Eureka to advertise the IP Adresses of services rather than the hostname. Set eureka.instance.preferIpAddress to true and when the application registers with eureka, it will use its IP Address rather than its hostname.
摘自官網(wǎng)
eureka.instance.preferIpAddress=true是通過設(shè)置ip讓eureka讓其他服務(wù)注冊它。也許能通過去改變?nèi)ネㄟ^改變host的方式。
此時的架構(gòu)圖:
Eureka-eserver peer1 8761,Eureka-eserver peer2 8769相互感應(yīng),當(dāng)有服務(wù)注冊時,兩個Eureka-eserver是對等的,它們都存有相同的信息,這就是通過服務(wù)器的冗余來增加可靠性,當(dāng)有一臺服務(wù)器宕機了,服務(wù)并不會終止,因為另一臺服務(wù)存有相同的數(shù)據(jù)。
感謝你能夠認(rèn)真閱讀完這篇文章,希望小編分享的“Spring Cloud如何實現(xiàn)高可用的服務(wù)注冊中心”這篇文章對大家有幫助,同時也希望大家多多支持創(chuàng)新互聯(lián),關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道,更多相關(guān)知識等著你來學(xué)習(xí)!
本文標(biāo)題:SpringCloud如何實現(xiàn)高可用的服務(wù)注冊中心
本文URL:http://jinyejixie.com/article36/pshgpg.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供微信小程序、品牌網(wǎng)站設(shè)計、營銷型網(wǎng)站建設(shè)、關(guān)鍵詞優(yōu)化、響應(yīng)式網(wǎng)站、Google
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)