首页 > 技术文章 > Eureka Server不剔除已关停的节点的问题

whuthxb 2018-06-21 10:25 原文

  由于Eureka拥有自我保护机制,当其注册表里服务因为网络或其他原因出现故障而关停时,Eureka不会剔除服务注册,而是等待其修复。这是AP的一种实现。

  自我保护机制:Eureka Server在运行期间,会统计心跳失败的比例在15分钟之内是否低于85%,如果出现低于的情况(在单机调试的时候很容易满足,实际在生产环境上通常是由于网络不稳定导致),Eureka Server会将当前的实例注册信息保护起来(该服务一直存在,且为UP状态),同时提示这个警告:EMERGENCY! EUREKA MAY BE INCORRECTLY CLAIMING INSTANCES ARE UP WHEN THEY'RE NOT. RENEWALS ARE LESSER THAN THRESHOLD AND HENCE THE INSTANCES ARE NOT BEING EXPIRED JUST TO BE SAFE.

  但是在开发过程中,我们常常希望Eureka Server能够迅速有效地踢出已关停的节点。

  常用方法有:

  一、关闭自我保护

  server端:

    eureka.server.enable-self-preservation//(设为false,关闭自我保护主要)

    eureka.server.eviction-interval-timer-in-ms//清理间隔(单位毫秒,默认是60*1000)

   client端:

    eureka.client.healthcheck.enabled = true//开启健康检查(需要spring-boot-starter-actuator依赖)

    eureka.instance.lease-renewal-interval-in-seconds =10//租期更新时间间隔(默认30秒)

    eureka.instance.lease-expiration-duration-in-seconds =30//租期到期时间(默认90秒)

  二、利用Eureka的rest管理端点下线服务

  eureka界面注册的服务:

    

  发送DELETE的Restfull请求

    

注意:由于cloud服务是心跳检测,所有在eureka进行DELETE后要快速的停止服务,否则服务可能会被重新注册上。

  三、利用Spring Boot Actuato的管理端点(推荐) 

  1、pom中引用Actuato

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

  2、properties中添加如下内容

#启用shutdown
endpoints.shutdown.enabled=true
#禁用密码验证
endpoints.shutdown.sensitive=false

  如果只允许本机访问,可以添加如下属性

#(只允许本机访问)
server.address=localhost

  3、在服务器上利用curl发送shutdown命令

curl -X POST http://localhost:8295/shutdown

或者

curl -d "" http://localhost:8295/shutdown

 

推荐阅读