springCloud Eureka 報錯解決方案
在根據大神的文章安裝eureka過程遇到些報錯,這裡記錄下比較好的解決方案
https://blog.csdn.net/forezp/article/details/70148833/
啟動Eureka server
直接啟動報錯:
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.
之後各種查詢開始查到一個方案
https://www.cnblogs.com/moonandstar08/p/6435710.html
感覺解釋的不是很清楚
開始直接 設定 eureka.server.enableSelfPreservation: false 結果又報錯:
THE SELF PRESERVATION MODE IS TURNED OFF.THIS MAY NOT PROTECT INSTANCE EXPIRY IN CASE OF NETWORK/OTHER PROBLEMS.
後來在stackoverflow上看到一個解釋的比較清楚的:
大概總結的方案是
- 部署兩臺Eureka伺服器並啟用
registerWithEureka
。 - 如果您只想在demo / dev環境中部署,則可以設定
eureka.server.renewalPercentThreshold
為0.49,因此當您單獨啟動Eureka伺服器時,閾值將為0。
下面是直接google翻譯的:
每個例項都需要將其租約更新到Eureka Server,頻率為每30秒一次,可以在其中定義eureka.instance.leaseRenewalIntervalInSeconds
續訂(最後一分鐘):表示在最後一分鐘從Eureka例項收到的續訂數量
續訂閾值:Eureka伺服器預期每分鐘從Eureka例項收到的續訂。
例如,如果registerWithEureka
設定為false,eureka.instance.leaseRenewalIntervalInSeconds
則設定為30並執行2 Eureka例項。兩個Eureka例項每分鐘將向Eureka伺服器傳送4次更新,Eureka伺服器最小閾值為1(用程式碼編寫),因此閾值為5(這個數字將乘以一個因子eureka.server.renewalPercentThreshold
,稍後將討論)。
自我儲存模式:如果續訂(最後一分鐘)小於續訂閾值,將啟用自我保護模式。
所以在上面的示例中,SELF PRESERVATION MODE被啟用,因為閾值是5,但Eureka伺服器只能接收4次更新/分鐘。
- 問題1:
SELF PRESERVATION MODE旨在避免網路連線故障。Eureka例項A和B之間的連線很好,但是由於連線問題,B很難在短時間內將租約更新到Eureka伺服器,此時Eureka伺服器不能簡單地啟動例項B.如果是,則例項儘管B可用,但無法從Eureka伺服器獲得註冊服務。所以這就是SELF PRESERVATION MODE的目的,最好將其開啟。
- 問題2:
最小閾值1寫在程式碼中。registerWithEureka
設定為false,因此沒有Eureka例項暫存器,閾值將為1。
在生產環境中,通常我們部署兩個Eureka伺服器並將registerWithEureka
設定為true。所以門檻將是2,Eureka伺服器將續租兩次/分鐘,所以RENEWALS ARE LESSER THAN THRESHOLD
不會有問題。
- 問題3:
你是對的。eureka.instance.leaseRenewalIntervalInSeconds
定義每分鐘傳送到伺服器的續訂次數,但它將乘以eureka.server.renewalPercentThreshold
上面提到的因子,預設值為0.85。
- 問題4:
是的,這是正常的,因為閾值初始值設定為1.因此,如果registerWithEureka
設定為false,則續訂總是低於閾值。
我有兩個建議:
- 部署兩臺Eureka伺服器並啟用
registerWithEureka
。 - 如果您只想在demo / dev環境中部署,則可以設定
eureka.server.renewalPercentThreshold
為0.49,因此當您單獨啟動Eureka伺服器時,閾值將為0。
原文:
Every instance needs to renew its lease to Eureka Server with frequency of one time per 30 seconds, which can be define in eureka.instance.leaseRenewalIntervalInSeconds
.
Renews (last min): represents how many renews received from Eureka instance in last minute
Renews threshold: the renews that Eureka server expects received from Eureka instance per minute.
For example, if registerWithEureka
is set to false, eureka.instance.leaseRenewalIntervalInSeconds
is set to 30 and run 2 Eureka instance. Two Eureka instance will send 4 renews to Eureka server per minutes, Eureka server minimal threshold is 1 (written in code), so the threshold is 5 (this number will be multiply a factor eureka.server.renewalPercentThreshold
which will be discussed later).
SELF PRESERVATION MODE: if Renews (last min) is less than Renews threshold, self preservation mode will be activated.
So in upper example, the SELF PRESERVATION MODE is activated, because threshold is 5, but Eureka server can only receive 4 renews/min.
- Question 1:
The SELF PRESERVATION MODE is design to avoid poor network connectivity failure. Connectivity between Eureka instance A and B is good, but B is failed to renew its lease to Eureka server in a short period due to connectivity hiccups, at this time Eureka server can't simply just kick out instance B. If it does, instance A will not get available registered service from Eureka server despite B is available. So this is the purpose of SELF PRESERVATION MODE, and it's better to turn it on.
- Question 2:
The minimal threshold 1 is written in the code. registerWithEureka
is set to false so there will be no Eureka instance registers, the threshold will be 1.
In production environment, generally we deploy two Eureka server and registerWithEureka
will be set to true. So the threshold will be 2, and Eureka server will renew lease to itself twice/minute, so RENEWALS ARE LESSER THAN THRESHOLD
won't be a problem.
- Question 3:
Yes, you are right. eureka.instance.leaseRenewalIntervalInSeconds
defines how many renews sent to server per minute, but it will multiply a factor eureka.server.renewalPercentThreshold
mentioned above, the default value is 0.85.
- Question 4:
Yes, it's normal, because the threshold initial value is set to 1. So if registerWithEureka
is set to false, renews is always below threshold.
I have two suggestions for this:
- Deploy two Eureka server and enable
registerWithEureka
. - If you just want to deploy in demo/dev environment, you can set
eureka.server.renewalPercentThreshold
to 0.49, so when you start up a Eureka server alone, threshold will be 0.