美文网首页
微服务优雅停机

微服务优雅停机

作者: 夜空最亮的9星 | 来源:发表于2019-04-21 10:26 被阅读0次

在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

相关文章

  • 微服务优雅停机

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

  • Dubbo服务之优雅停机

    服务提供方停止时,先标记为不接收新请求,新请求过来时直接报错,让客户端重试其它机器。然后,检测线程池中的线程是否正...

  • Spring优雅停止服务的实现及原理分析

    背景 服务能被优雅停机,指的是:在接收到停机指令后,服务程序应该能拒绝新的请求, 但应该继续完成已经接收请求。 解...

  • SpringCloud微服务如何优雅停机及源码分析

    [SpringCloud微服务如何优雅停机及源码分析] ( 原文链接:https://www.cnblogs.co...

  • Dubbo在Docker中的优雅停机

    Dubbo在Docker中的优雅停机 优雅停机 优雅停机是指在停止应用时,执行的一系列保证应用正常关闭的操作。这些...

  • Dubbo ShutdownHook 优雅停机整理

    Dubbo优雅停机的机制 Dubbo是通过JDK的ShutdownHook来完成优雅停机的所以如果用户使用 kil...

  • consul注销微服务实例

    当我们的微服务优雅停机时,consul客户端会自动注销当前的微服务实例: Spring提供2种方式:实现Dispo...

  • 《RPC实战与核心原理》学习笔记Day11

    13 | 优雅关闭:如何避免服务停机带来的业务损失? 我们在RPC架构下,需要考虑当服务重启时,如何做到让调用方系...

  • 微服务部署与优雅停机

    00 前言 微服务部署是一个非常严谨的话题,微服务开发完成需要上线部署,在整个部署过程中怎么保证业务的连续性,怎么...

  • dubbo - 优雅停机

    开篇 这篇文章主要的目的是想分析下dubbo优雅停机的过程,整个文章参考网上很多现成的文章,本着尊重原创的精神会在...

网友评论

      本文标题:微服务优雅停机

      本文链接:https://www.haomeiwen.com/subject/bpydgqtx.html