不间断重启springboot项目

前提:

服务至少要部署两台机上,当其中一台下线后,由另一台提供对外服务

 

1,依赖

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.2.2.RELEASE</version>
</parent>


 <dependencies>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
        </dependency>

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

        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-hystrix</artifactId>
        </dependency>

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




 <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-dependencies</artifactId>
                <version>Hoxton.SR3</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>


        </dependencies>
    </dependencyManagement>

 

application.yml 配置

management.endpoint.shutdown.enabled=true
management.endpoint.health.show-details=always
management.endpoints.web.exposure.include=*

 

 

#微服务上线请求

curl -H "Content-Type:application/vnd.spring-boot.actuator.v2+json;charset=UTF-8" -X POST http://localhost:2{{ port }}/actuator/service-registry?status=UP

 



#2.x版本微服务下线请求
curl -H "Content-Type:application/vnd.spring-boot.actuator.v2+json;charset=UTF-8" -X POST http://localhost:2890/actuator/service-registry?status=DOWN
#1.x版本微服务下线请求
curl -X POST -H 'Content-Type: application/json'  -d 'DOWN' "http://localhost:8003/service-registry/instance-status"

 


#eureka 小知识
>eureka 清理过期服务的时间间隔是0s,即不清理实例
eureka.server.eviction-interval-timer-in-ms 

 



>eureka 客户端配置

eureka 服务端如果发现客户端在这个时间段内没有收到心跳,会将客户端下线
默认值90s
eureka.instance.lease-expiration-duration-in-seconds

 


>客户端通过eureka.instance.lease-renewal-interval-in-seconds
每隔这个时间会主动心跳一次,默认值为30s,更新自己的状态。

 

posted @ 2021-05-03 17:08  冬马党  阅读(627)  评论(0编辑  收藏  举报