javascript
怎么关闭eureka的服务_SpringCloud微服务踩坑系列之二
一.關(guān)于Eureka和Config服務(wù)的logback.xml配置文件問題
注意:在eureka和config服務(wù)中,如果使用logback.xml配置文件,會(huì)導(dǎo)致在服務(wù)啟動(dòng)的時(shí)候出現(xiàn)如下warn警告信息,尤其是config服務(wù),更嚴(yán)重的會(huì)導(dǎo)致服務(wù)無法啟動(dòng).
2018-10-09 15:09:32.738 WARN 8176 --- [ost-startStop-1] c.n.c.sources.URLConfigurationSource : No URLs will be polled as dynamic configuration sources. 2018-10-09 15:09:34.113 WARN 8176 --- [ main] o.s.c.n.a.ArchaiusAutoConfiguration : No spring.application.name found, defaulting to 'application' 2018-10-09 15:09:34.113 WARN 8176 --- [ main] c.n.c.sources.URLConfigurationSource : No URLs will be polled as dynamic configuration sources. 2018-10-09 15:09:34.971 WARN 8176 --- [ main] c.n.eureka.cluster.PeerEurekaNodes : The replica size seems to be empty. Check the route 53 DNS Registry二.關(guān)于"Process finished with exit code 0"的問題
在SpringBoot項(xiàng)目啟動(dòng)時(shí),控制臺(tái)中可能會(huì)出現(xiàn)"Process finished with exit code 0"這樣的日志信息,這樣的信息意味著你的程序正常執(zhí)行完畢并退出。
可以科普一下exit code,在大部分編程語言中都適用.
exit code 0 表示程序執(zhí)行成功,正常退出;
exit code 1 表示程序執(zhí)行執(zhí)行過程中遇到了某些問題或者錯(cuò)誤,非正常退出.
在SpringBoot啟動(dòng)時(shí)如果出現(xiàn)"Process finished with exit code 0",有可能是項(xiàng)目中沒有添加spring-boot-starter-web依賴包導(dǎo)致的.
解決方法,引入依賴:
<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId> </dependency>三.RENEWALS ARE LESSER THAN THE THRESHOLD問題
啟動(dòng)兩個(gè)client,過了一會(huì),停了其中一個(gè),訪問注冊(cè)中心時(shí),界面上顯示了上面的警告信息:
Eureka server和client之間每隔30秒會(huì)進(jìn)行一次心跳通信,告訴server,client還活著。由此引出兩個(gè)名詞:
Renews threshold:server期望在每分鐘中收到的心跳次數(shù)
Renews (last min):上一分鐘內(nèi)收到的心跳次數(shù)。
前文說到禁止注冊(cè)server自己為client,不管server是否禁止,閾值(threshold)是1。client個(gè)數(shù)為n,閾值為1+2*n(此為一個(gè)server且禁止自注冊(cè)的情況)
如果是多個(gè)server,且開啟了自注冊(cè),那么就和client一樣,是對(duì)于其他的server來說就是client,是要*2的
我開了兩個(gè)server,自注冊(cè),相關(guān)數(shù)據(jù)如下
閾值:1+2*1
renews:
1)自注冊(cè) 2 + 2*1
2)非自注冊(cè):2*1
Eurake有一個(gè)配置參數(shù)eureka.server.renewalPercentThreshold,定義了renews 和renews threshold的比值,默認(rèn)值為0.85。當(dāng)server在15分鐘內(nèi),比值低于percent,即少了15%的微服務(wù)心跳,server會(huì)進(jìn)入自我保護(hù)狀態(tài),Self-Preservation。在此狀態(tài)下,server不會(huì)刪除注冊(cè)信息,這就有可能導(dǎo)致在調(diào)用微服務(wù)時(shí),實(shí)際上服務(wù)并不存在。
這種保護(hù)狀態(tài)實(shí)際上是考慮了client和server之間的心跳是因?yàn)榫W(wǎng)絡(luò)問題,而非服務(wù)本身問題,不能簡(jiǎn)單的刪除注冊(cè)信息
stackoverflow上,有人給出的建議是:
1、在生產(chǎn)上可以開自注冊(cè),部署兩個(gè)server
2、在本機(jī)器上測(cè)試的時(shí)候,可以把比值調(diào)低,比如0.49
3、或者簡(jiǎn)單粗暴把自我保護(hù)模式關(guān)閉
四.TransportException: Cannot execute request on any known server問題
升級(jí)到新版的SpringCloud之后,當(dāng)eureka注冊(cè)中心配置了security的依賴
<!--注意:SpringBoot項(xiàng)目遵循的是約定大于配置的原則,當(dāng)此處添加了security的依賴后,就會(huì)自動(dòng)啟用eureka的安全驗(yàn)證功能,否則就不開啟--> <dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-security</artifactId> </dependency>之后,可能會(huì)導(dǎo)致一些問題,比如就可能會(huì)導(dǎo)致在啟動(dòng)eureka客戶端的時(shí)候產(chǎn)生"TransportException: Cannot execute request on any known server"異常,使得eureka客戶端無法連接注冊(cè)中心.原因是新版的security默認(rèn)啟用了csrf檢驗(yàn),會(huì)對(duì)注冊(cè)到注冊(cè)中心的實(shí)例進(jìn)行csrf攔截,所以在客戶端連接eureka注冊(cè)中心的時(shí)候,默認(rèn)情況下會(huì)導(dǎo)致Cannot execute request on any known server問題
解決辦法:
1.在eureka服務(wù)端代碼中配置security的csrf檢驗(yàn)為false; 2.客戶端中以用戶名密碼形式登錄:client:service-url:defaultZone: http://admin:syc@localhost:1001/eureka/@EnableWebSecurity public class WebSecurityConfig extends WebSecurityConfigurerAdapter {/*** 新版的security默認(rèn)啟用了csrf檢驗(yàn),所以在客戶端連接eureka注冊(cè)中心的時(shí)候,默認(rèn)情況下會(huì)導(dǎo)致 * Cannot execute request on any known server問題.* 解決辦法:* 1.在eureka服務(wù)端代碼中配置security的csrf檢驗(yàn)為false;* 2.客戶端中以用戶名密碼形式登錄:* client:* service-url:* defaultZone: http://admin:syc@localhost:1001/eureka/*/@Overrideprotected void configure(HttpSecurity http) throws Exception {/*直接關(guān)閉crsf功能:http.csrf().disable();*//*對(duì)eureka的訪問放行*/http.csrf().ignoringAntMatchers("/eureka/**");super.configure(http);} }eureka:client:service-url:#defaultZone: http://localhost:1001/eureka/defaultZone: http://admin:syc@localhost:1001/eureka/總結(jié)
以上是生活随笔為你收集整理的怎么关闭eureka的服务_SpringCloud微服务踩坑系列之二的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: stm32如何执行软复位_stm32 上
- 下一篇: 三位分节制顺口溜_1-3年级基础知识顺口