日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 >

Spring Cloud中,Eureka常见问题总结

發(fā)布時(shí)間:2025/3/15 53 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Spring Cloud中,Eureka常见问题总结 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

Spring Cloud中,Eureka常見問題總結(jié)。

1 eureka.environment: 指定環(huán)境

參考文檔:

1 eureka.datacenter: 指定數(shù)據(jù)中心

參考文檔: 使用配置項(xiàng):

1
eureka.instance.leaseRenewalIntervalInSeconds

參考文檔:

1 2 3 Why is it so Slow to Register a Service? Being an instance also involves a periodic heartbeat to the registry (via the client’s serviceUrl) with default duration 30 seconds. A service is not available for discovery by clients until the instance, the server and the client all have the same metadata in their local cache (so it could take 3 heartbeats). You can change the period using eureka.instance.leaseRenewalIntervalInSeconds and this will speed up the process of getting clients connected to other services. In production it’s probably better to stick with the default because there are some computations internally in the server that make assumptions about the lease renewal period.

翻譯:

1
作為實(shí)例還涉及到與注冊(cè)中心的周期性心跳,默認(rèn)持續(xù)時(shí)間為30秒(通過serviceUrl)。在實(shí)例、服務(wù)器、客戶端都在本地緩存中具有相同的元數(shù)據(jù)之前,服務(wù)不可用于客戶端發(fā)現(xiàn)(所以可能需要3次心跳)。你可以使用eureka.instance.leaseRenewalIntervalInSeconds 配置,這將加快客戶端連接到其他服務(wù)的過程。在生產(chǎn)中,最好堅(jiān)持使用默認(rèn)值,因?yàn)樵诜?wù)器內(nèi)部有一些計(jì)算,他們對(duì)續(xù)約做出假設(shè)。

如果在Eureka Server的首頁看到以下這段提示,則說明Eureka已經(jīng)進(jìn)入了保護(hù)模式。

?

1
EMERGENCY!?EUREKA?MAY?BE?INCORRECTLY?CLAIMING?INSTANCES?ARE?UP?WHEN?THEY'RE?NOT.?RENEWALS?ARE?LESSER?THAN?THRESHOLD?AND?HENCE?THE?INSTANCES?ARE?NOT?BEING?EXPIRED?JUST?TO?BE?SAFE.

保護(hù)模式主要用于一組客戶端和Eureka Server之間存在網(wǎng)絡(luò)分區(qū)場(chǎng)景下的保護(hù)。一旦進(jìn)入保護(hù)模式,Eureka Server將會(huì)嘗試保護(hù)其服務(wù)注冊(cè)表中的信息,不再刪除服務(wù)注冊(cè)表中的數(shù)據(jù)(也就是不會(huì)注銷任何微服務(wù))。

詳見: 在開發(fā)過程中,我們常常希望Eureka Server能夠迅速有效地踢出已關(guān)停的節(jié)點(diǎn),但是新手由于Eureka自我保護(hù)模式,以及心跳周期長(zhǎng)的原因,常常會(huì)遇到Eureka Server不踢出已關(guān)停的節(jié)點(diǎn)的問題。解決方法如下:

(1) Eureka Server端:配置關(guān)閉自我保護(hù),并按需配置Eureka Server清理無效節(jié)點(diǎn)的時(shí)間間隔。

1 2
eureka.server.enable-self-preservation # 設(shè)為false,關(guān)閉自我保護(hù) eureka.server.eviction-interval-timer-in-ms # 清理間隔(單位毫秒,默認(rèn)是60*1000)

(2) Eureka Client端:配置開啟健康檢查,并按需配置續(xù)約更新時(shí)間和到期時(shí)間。

1 2 3
eureka.client.healthcheck.enabled # 開啟健康檢查(需要spring-boot-starter-actuator依賴) eureka.instance.lease-renewal-interval-in-seconds # 續(xù)約更新時(shí)間間隔(默認(rèn)30秒) eureka.instance.lease-expiration-duration-in-seconds # 續(xù)約到期時(shí)間(默認(rèn)90秒)

示例:
服務(wù)器端配置:

1 2 3 4
eureka: server: enable-self-preservation: false eviction-interval-timer-in-ms: 4000

客戶端配置:

1 2 3 4 5 6 7
eureka: client: healthcheck: enabled: true instance: lease-expiration-duration-in-seconds: 30 lease-renewal-interval-in-seconds: 10

注意:
更改Eureka更新頻率將打破服務(wù)器的自我保護(hù)功能,生產(chǎn)環(huán)境下不建議自定義這些配置。
詳見: 在Spring Cloud中,服務(wù)的Instance ID的默認(rèn)值是${spring.cloud.client.hostname}:${spring.application.name}:${spring.application.instance_id:${server.port}}?,也就是機(jī)器主機(jī)名:應(yīng)用名稱:應(yīng)用端口?。因此在Eureka Server首頁中看到的服務(wù)的信息類似如下:itmuch:microservice-provider-user:8000?。如果想要自定義這部分的信息怎么辦?

示例:

eureka:client:serviceUrl:defaultZone: http://localhost:8761/eureka/instance:preferIpAddress: trueinstance-id: ${spring.cloud.client.ipAddress}:${server.port} # 將Instance ID設(shè)置成IP:端口的形式

eureka.client.healthcheck.enabled=true?只應(yīng)該在application.yml中設(shè)置。如果設(shè)置在bootstrap.yml中將會(huì)導(dǎo)致一些不良的副作用,例如在Eureka中注冊(cè)的應(yīng)用名稱是UNKNOWN等。

?

?

轉(zhuǎn)自:http://www.itmuch.com/spring-cloud-sum-eureka/

轉(zhuǎn)載于:https://www.cnblogs.com/leleroyn/p/7943861.html

總結(jié)

以上是生活随笔為你收集整理的Spring Cloud中,Eureka常见问题总结的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。