這篇文章主要介紹“SpringCloud怎么將Eureka Server集群化”,在日常操作中,相信很多人在SpringCloud怎么將Eureka Server集群化問題上存在疑惑,小編查閱了各式資料,整理出簡單好用的操作方法,希望對(duì)大家解答”SpringCloud怎么將Eureka Server集群化”的疑惑有所幫助!接下來,請(qǐng)跟著小編一起來學(xué)習(xí)吧!
一、準(zhǔn)備工作
Eureka can be made even more resilient and available by running multiple instances and asking them to register with each other. Infact, 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通過運(yùn)行多個(gè)實(shí)例,使其更具有高可用性。事實(shí)上,這是它默認(rèn)的熟性,你需要做的就是給對(duì)等的實(shí)例一個(gè)合法的關(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)建另外一個(gè)配置文件application-peer2.yml:
server: port: 8769 spring: profiles: peer2 eureka: instance: hostname: peer2 client: serviceUrl: defaultZone: http://peer1:8761/eureka/
這時(shí)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 修改。
這時(shí)需要改造下service-hi:
eureka: client: serviceUrl: defaultZone: http://peer1:8761/eureka/ server: port: 8762 spring: application: name: service-hi
三、啟動(dòng)工程
啟動(dòng)eureka-server:
java -jar eureka-server-0.0.1-SNAPSHOT.jar --spring.profiles.active=peer1
啟動(dòng)service-hi:
java -jar service-hi-0.0.1-SNAPSHOT.jar
訪問:localhost:8761,如圖:
你會(huì)發(fā)現(xiàn)注冊(cè)了service-hi,并且有個(gè)peer2節(jié)點(diǎn),同理訪問localhost:8769你會(huì)發(fā)現(xiàn)有個(gè)peer1節(jié)點(diǎn)。
client只向8761注冊(cè),但是你打開8769,你也會(huì)發(fā)現(xiàn),8769也有 client的注冊(cè)信息。
個(gè)人感受:這是通過看官方文檔的寫的demo ,但是需要手動(dòng)改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 hostname.——摘自官網(wǎng)
eureka.instance.preferIpAddress=true是通過設(shè)置ip讓eureka讓其他服務(wù)注冊(cè)它。也許能通過去改變?nèi)ネㄟ^改變host的方式。
此時(shí)的架構(gòu)圖:
Eureka-eserver peer1 8761,Eureka-eserver peer2 8769相互感應(yīng),當(dāng)有服務(wù)注冊(cè)時(shí),兩個(gè)Eureka-eserver是對(duì)等的,它們都存有相同的信息,這就是通過服務(wù)器的冗余來增加可靠性,當(dāng)有一臺(tái)服務(wù)器宕機(jī)了,服務(wù)并不會(huì)終止,因?yàn)榱硪慌_(tái)服務(wù)存有相同的數(shù)據(jù)。
到此,關(guān)于“SpringCloud怎么將Eureka Server集群化”的學(xué)習(xí)就結(jié)束了,希望能夠解決大家的疑惑。理論與實(shí)踐的搭配能更好的幫助大家學(xué)習(xí),快去試試吧!若想繼續(xù)學(xué)習(xí)更多相關(guān)知識(shí),請(qǐng)繼續(xù)關(guān)注創(chuàng)新互聯(lián)-成都網(wǎng)站建設(shè)公司網(wǎng)站,小編會(huì)繼續(xù)努力為大家?guī)砀鄬?shí)用的文章!
本文名稱:SpringCloud怎么將EurekaServer集群化-創(chuàng)新互聯(lián)
URL鏈接:http://chinadenli.net/article16/dosigg.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供移動(dòng)網(wǎng)站建設(shè)、網(wǎng)站營銷、App設(shè)計(jì)、標(biāo)簽優(yōu)化、微信公眾號(hào)、動(dòng)態(tài)網(wǎng)站
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)