springcloud中微服務(wù)的優(yōu)雅停機

在springcloud微服務(wù)架構(gòu)中,如果我們想停止某個微服務(wù)實例,最好不用用kill -9 服務(wù)pid?的方法暴力殺死進程。

如果直接kill -9 Springcloud的服務(wù),因為Eureka采用心跳的機制來上下線服務(wù),會導(dǎo)致服務(wù)消費者調(diào)用此已經(jīng)kill的服務(wù)提供者,然后出錯。

springboot1.x?中微服務(wù)優(yōu)雅停機的配置:

1、?在微服務(wù)pom.xml文件中,配置spring-boot-starter-actuator?監(jiān)控組件

? ??<dependency>

? ? <groupId>org.springframework.boot</groupId>

? ? <artifactId>spring-boot-starter-actuator</artifactId>

</dependency>

2 、application.yml中配置

endpoints.shutdown.enabled:? true? #啟用shutdown端點,以便支持優(yōu)雅停機

#endpoints.shutdown.sensitive:? false? #禁用密碼驗證(可選)

3、在任意一臺服務(wù)器上利用curl發(fā)送shutdown命令

curl -X POST http://ip:端口/shutdown

或者

curl -d "" http://ip:端口/shutdown


================================

springboot2.x?中微服務(wù)優(yōu)雅停機配置


1、?在微服務(wù)pom.xml文件中,配置spring-boot-starter-actuator?監(jiān)控組件

<dependency>

? ? <groupId>org.springframework.boot</groupId>

? ? <artifactId>spring-boot-starter-actuator</artifactId>

</dependency>

2、application.yml配置

#管理端點

management:?

#? endpoints:

#? ? web:

#? ? ? base-path: /actuator? #默認為 /actuator

? endpoints:?

? ? web:

? ? ? exposure:

? ? ? ? include:

? ? ? ? - shutdown

? ? ? ? - info

? ? ? ? - health

? endpoint:

? ? shutdown:

? ? ? enabled: true

#配置management的自定義端口,可以與server.port不同,?

#management.server.port: 8081

#management.server.address: 127.0.0.1 # management只能在本機訪問

3、在任意一臺服務(wù)器上利用curl發(fā)送shutdown命令

curl? -X POST http://ip:端口/actuator/shutdown?

原文鏈接:https://blog.csdn.net/jasnet_u/article/details/84873829

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容