公眾號(hào): java樂(lè)園
為郎溪等地區(qū)用戶提供了全套網(wǎng)頁(yè)設(shè)計(jì)制作服務(wù),及郎溪網(wǎng)站建設(shè)行業(yè)解決方案。主營(yíng)業(yè)務(wù)為成都網(wǎng)站設(shè)計(jì)、網(wǎng)站建設(shè)、外貿(mào)網(wǎng)站建設(shè)、郎溪網(wǎng)站設(shè)計(jì),以傳統(tǒng)方式定制建設(shè)網(wǎng)站,并提供域名空間備案等一條龍服務(wù),秉承以專業(yè)、用心的態(tài)度為用戶提供真誠(chéng)的服務(wù)。我們深信只要達(dá)到每一位用戶的要求,就會(huì)得到認(rèn)可,從而選擇與我們長(zhǎng)期合作。這樣,我們也可以走得更遠(yuǎn)!1、 Eureka作為spring cloud的服務(wù)發(fā)現(xiàn)與注冊(cè)中心,在整個(gè)的微服務(wù)體系中,處于核心位置。單機(jī)模式下的eureka服務(wù),顯然不能滿足高可用的實(shí)際生產(chǎn)環(huán)境,這就要求配置一個(gè)能夠應(yīng)對(duì)各種突發(fā)情況,具有較強(qiáng)容災(zāi)能力的eureka服務(wù)。Eureka通過(guò)“伙伴機(jī)制”實(shí)現(xiàn)高可用。每一臺(tái)Eureka都需要在配置中指定另外兩個(gè)Eureka的地址伙伴,Eureka啟動(dòng)時(shí)會(huì)向自己的伙伴節(jié)點(diǎn)獲取當(dāng)前已經(jīng)存在的注冊(cè)表,這樣在向Eureka集群中新加機(jī)器時(shí)就不需要擔(dān)心注冊(cè)表的不完整。
2、 新建三個(gè)maven項(xiàng)目,分別為sc-eureka-cluster-server-node1,sc-eureka-cluster-server-node2,sc-eureka-cluster-server-node3。項(xiàng)目結(jié)構(gòu)如下:
備注:pom.xml和EurekaServerApplication.java的內(nèi)容給單機(jī)模式是一模一樣的,請(qǐng)參考上篇文章。
3、 主要看下bootstap.yml或者application.yml文件的改動(dòng)
sc-eureka-cluster-server-node1
spring:
application:
name: sc-eureka-cluster-server-node1
server:
port: 5001
eureka:
instance:
hostname: sc-eureka-cluster-server-node1
lease-renewal-interval-in-seconds: 30
lease-expiration-duration-in-seconds: 30
prefer-ip-address: true
client:
registerWithEureka: false
fetchRegistry: false
serviceUrl:
defaultZone: http://sc-eureka-cluster-server-node2:5002/eureka/,http://sc-eureka-cluster-server-node3:5003/eureka/
sc-eureka-cluster-server-node2
spring:
application:
name: sc-eureka-cluster-server-node2
server:
port: 5002
eureka:
instance:
hostname: sc-eureka-cluster-server-node2
lease-renewal-interval-in-seconds: 30
lease-expiration-duration-in-seconds: 30
prefer-ip-address: true
client:
registerWithEureka: false
fetchRegistry: false
serviceUrl:
defaultZone: http://sc-eureka-cluster-server-node1:5001/eureka/,http://sc-eureka-cluster-server-node3:5003/eureka/
sc-eureka-cluster-server-node3
spring:
application:
name: sc-eureka-cluster-server-node3
server:
port: 5003
eureka:
instance:
hostname: sc-eureka-cluster-server-node3
lease-renewal-interval-in-seconds: 30
lease-expiration-duration-in-seconds: 30
prefer-ip-address: true
client:
registerWithEureka: false
fetchRegistry: false
serviceUrl:
defaultZone: http://sc-eureka-cluster-server-node1:5001/eureka/,http://sc-eureka-cluster-server-node2:5001/eureka/
4、 配置host文件C:\Windows\System32\drivers\etc\hosts
127.0.0.1 sc-eureka-cluster-server-node1
127.0.0.1 sc-eureka-cluster-server-node2
127.0.0.1 sc-eureka-cluster-server-node3
5、 分別啟動(dòng)EurekaServerApplication.java
sc-eureka-cluster-server-node1的日志:
sc-eureka-cluster-server-node2的日志:
sc-eureka-cluster-server-node3的日志
如果出現(xiàn)上面圈住的日志說(shuō)明啟動(dòng)成功
6、 在瀏覽器分別訪問(wèn)
http://sc-eureka-cluster-server-node1:5001/
http://sc-eureka-cluster-server-node2:5002/
http://sc-eureka-cluster-server-node3:5002/
下面列出幾個(gè)重要的配置項(xiàng)類:
org.springframework.boot.autoconfigure.web.ServerProperties
org.springframework.cloud.netflix.eureka.EurekaInstanceConfigBean
com.netflix.eureka.EurekaServerConfig
com.netflix.eureka.DefaultEurekaServerConfig
org.springframework.cloud.netflix.eureka.server.EurekaServerConfigBean
com.netflix.discovery.EurekaClientConfig
com.netflix.discovery.DefaultEurekaClientConfig
org.springframework.cloud.netflix.eureka.EurekaClientConfigBean
創(chuàng)新互聯(lián)www.cdcxhl.cn,專業(yè)提供香港、美國(guó)云服務(wù)器,動(dòng)態(tài)BGP最優(yōu)骨干路由自動(dòng)選擇,持續(xù)穩(wěn)定高效的網(wǎng)絡(luò)助力業(yè)務(wù)部署。公司持有工信部辦法的idc、isp許可證, 機(jī)房獨(dú)有T級(jí)流量清洗系統(tǒng)配攻擊溯源,準(zhǔn)確進(jìn)行流量調(diào)度,確保服務(wù)器高可用性。佳節(jié)活動(dòng)現(xiàn)已開啟,新人活動(dòng)云服務(wù)器買多久送多久。