在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