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

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

如果直接kill -9 Springcloud的服務,因為Eureka采用心跳的機制來上下線服務,會導致服務消費者調用此已經kill的服務提供者,然后出錯。

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

1、?在微服務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、在任意一臺服務器上利用curl發(fā)送shutdown命令

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

或者

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


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

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


1、?在微服務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、在任意一臺服務器上利用curl發(fā)送shutdown命令

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

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

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

相關閱讀更多精彩內容

友情鏈接更多精彩內容