Eureka健康檢查和安全配置
Eureka 健康檢查
由于server和client通過心跳保持 服務(wù)狀態(tài),而只有狀態(tài)為UP的服務(wù)才能被訪問??磂ureka界面中的status。
比如心跳一直正常,服務(wù)一直UP,但是此服務(wù)DB連不上了,無(wú)法正常提供服務(wù)。
此時(shí),我們需要將微服務(wù)的健康狀態(tài)也同步到server。只需要啟動(dòng)eureka的健康檢查就行。這樣微服務(wù)就會(huì)將自己的健康狀態(tài)同步到eureka。配置如下即可。
eureka.client.healthcheck.enabled=true
可以改變服務(wù)的狀態(tài),只需實(shí)現(xiàn)HealthIndicator接口即可。需要添加依賴
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-actuator</artifactId> </dependency>
HealthStatusService
@Service public class HealthStatusService implements HealthIndicator { private Boolean status = true; public void setStatus(Boolean status) { this.status = status; } @Override public Health health() { if (status) return new Health.Builder().up().build(); return new Health.Builder().down().build(); } public String getStatus() { return this.status.toString(); } }
測(cè)試Controller:
@GetMapping("/health") public String health(@RequestParam("status") Boolean status) { healthStatusSrv.setStatus(status); return healthStatusSrv.getStatus(); }
訪問http://localhost:8001/health?status=false,在訪問http://localhost:8761/,等待30秒左右即可看到:
consumer服務(wù)的狀態(tài)變?yōu)閐own。
訪問http://localhost:8001/health?status=true,在訪問http://localhost:8761/,等待30秒左右即可看到:
可以通過這種方式控制服務(wù)的狀態(tài)。
安全配置
如果Eureka Service加入了Spring Security依賴,那么客戶端訪問的時(shí)候必須攜帶用戶名和密碼。比如:eureka.client.service-url.defaultZone=http://user:123@localhost:8761/eureka/。
并且Eureka Service必須關(guān)閉Spring Security的csrf配置:
@Configuration @EnableWebSecurity public class MySecurityConfig extends WebSecurityConfigurerAdapter { @Override protected void configure(HttpSecurity http) throws Exception { http.csrf().disable(); super.configure(http); } }
否則注冊(cè)服務(wù)會(huì)報(bào)錯(cuò)。
相關(guān)知識(shí)
Eureka心跳健康檢查機(jī)制
Eureka自我保護(hù)機(jī)制、健康檢查的作用、actuator模塊監(jiān)控
Eureka心跳健康檢查機(jī)制與自我保護(hù)機(jī)制
揭秘微服務(wù)健康檢查:如何保障系統(tǒng)穩(wěn)定運(yùn)行的關(guān)鍵一步
健康檢查配置
為本地IDC和VBR配置健康檢查
VPN 連接 配置健康檢查
nginx配置后端服務(wù)健康檢查 nginx健康檢查模塊
容器啟動(dòng)健康檢查的配置 – PingCode
配置健康檢查探測(cè)物理專線連通性
網(wǎng)址: Eureka健康檢查和安全配置 http://www.u1s5d6.cn/newsview1393583.html
推薦資訊
- 1發(fā)朋友圈對(duì)老公徹底失望的心情 12775
- 2BMI體重指數(shù)計(jì)算公式是什么 11235
- 3補(bǔ)腎吃什么 補(bǔ)腎最佳食物推薦 11199
- 4性生活姿勢(shì)有哪些 盤點(diǎn)夫妻性 10428
- 5BMI正常值范圍一般是多少? 10137
- 6在線基礎(chǔ)代謝率(BMR)計(jì)算 9652
- 7一邊做飯一邊躁狂怎么辦 9138
- 8從出汗看健康 出汗透露你的健 9063
- 9早上怎么喝水最健康? 8613
- 10五大原因危害女性健康 如何保 7828
- 今日水素:陽(yáng)臺(tái)菜園,居家種出健康芽菜指南
- 運(yùn)動(dòng)女孩的休閑穿搭
- 《居家健康監(jiān)測(cè)證明》可在“隨申辦”在線開
- 【便民提示】在線開具“居家健康監(jiān)測(cè)證明”
- 健身休閑館如何經(jīng)營(yíng)管理
- 這個(gè)集運(yùn)動(dòng)、休閑、時(shí)尚為一體的運(yùn)動(dòng)品牌進(jìn)
- 知名運(yùn)動(dòng)休閑服裝品牌
- 江北新區(qū)兩案例入選省級(jí)居家社區(qū)養(yǎng)老服務(wù)典
- 康健園·戰(zhàn)“疫”|慢性病患者如何做好居家
- 北京啟明康健休閑健身中心 (北京市豐臺(tái)區(qū)