springcloud中微服务的优雅停机

在springcloud微服务架构中,如果我们想停止某个微服务实例,最好不用用kill -9 服务pid 的方法暴力杀死进程。

如果直接kill -9 Springcloud的服务,因为Eureka采用心跳的机制来上下线服务,会导致服务消费者调用此已经kill的服务提供者,然后出错。

springboot1.x 中微服务优雅停机的配置:

1、 在微服务pom.xml文件中,配置spring-boot-starter-actuator 监控组件

    <dependency>

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

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

</dependency>

2 、application.yml中配置

endpoints.shutdown.enabled:  true  #启用shutdown端点,以便支持优雅停机

#endpoints.shutdown.sensitive:  false  #禁用密码验证(可选)

3、在任意一台服务器上利用curl发送shutdown命令

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

或者

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


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

springboot2.x 中微服务优雅停机配置


1、 在微服务pom.xml文件中,配置spring-boot-starter-actuator 监控组件

<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发送shutdown命令

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

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

©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容