博客详情

springcloud中微服务的优雅停机 (原创)

作者: 朝如青丝暮成雪
发布时间:2018-12-07 11:22:38  文章分类:springcloud   阅读(1472)  评论(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 



关键字:  springcloud  优雅停机
评论信息
暂无评论
发表评论

亲,您还没有登陆,暂不能评论哦! 去 登陆 | 注册

博主信息
   
数据加载中,请稍候...
文章分类
   
数据加载中,请稍候...
阅读排行
 
数据加载中,请稍候...
评论排行
 
数据加载中,请稍候...

Copyright © 叮叮声的奶酪 版权所有
备案号:鄂ICP备17018671号-1

鄂公网安备 42011102000739号