springBoot优雅停服务配置

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

 <dependency>
   <groupId>org.springframework.boot</groupId>
   <artifactId>spring-boot-starter-actuator</artifactId>
 </dependency>

2、application.yml 配置文件中加入:

#优雅停服务配置
management:
  endpoint:
    shutdown:
      enabled: true  #启用shutdown
  endpoints:
    web:
      exposure:
        include: "*"
      base-path: /actuator #自定义管理端点的前缀(保证安全)
  server:
    port: ${server.port}
    address: 127.0.0.1 #不允许远程管理连接(不允许外部调用保证安全)

3、shell脚本:

shutdown.sh`

#!/bin/sh
echo "stopping application...."
curl -X POST 127.0.0.1:xxxx/actuator/shutdown
tail -f nohup.out

start.sh

#!/bin/bash
echo "running...."
cd /xxx/xxx/
nohup java -jar xxxxxx.jar >/xxx/xxx/nohup.out &
echo "running finish"
tail -f nohup.out
posted @   一勺兔子  阅读(266)  评论(0编辑  收藏  举报
编辑推荐:
· Java 中堆内存和栈内存上的数据分布和特点
· 开发中对象命名的一点思考
· .NET Core内存结构体系(Windows环境)底层原理浅谈
· C# 深度学习:对抗生成网络(GAN)训练头像生成模型
· .NET 适配 HarmonyOS 进展
阅读排行:
· 本地部署 DeepSeek:小白也能轻松搞定!
· 如何给本地部署的DeepSeek投喂数据,让他更懂你
· 从 Windows Forms 到微服务的经验教训
· 李飞飞的50美金比肩DeepSeek把CEO忽悠瘸了,倒霉的却是程序员
· 超详细,DeepSeek 接入PyCharm实现AI编程!(支持本地部署DeepSeek及官方Dee
Live2D
欢迎阅读『springBoot优雅停服务配置』
点击右上角即可分享
微信分享提示