尤里卡检测服务状态

上下文

我们使用Spring Cloud Netflix和Eureka作为服务发现,使用Zuul代理服务并对它们进行负载均衡。

微服务使用NodeJS实现,并使用NPM模块eureka-js-client在Eureka上注册,其间有一个自定义层,用于处理配置和所有微服务通用的内容。


问题

问题是Eureka无法识别是否有一项服务出现问题。 这是一个问题,因为我们正在拥有一个具有自动部署的开发基础架构,每次重新部署并重新启动不同端口上的微服务而无需重新启动Eureka(和Zuul)。

因此,过了一段时间,我们有一个微服务的十个或更多实例,其中只有一个上升,但所有被认为是上升。


解决方法

  1. 我尝试在客户端上设置heartbeatInterval较小,但这没有帮助。

  2. 我尝试在服务器上设置renewalThresholdUpdateIntervalMs较小,但这也无济于事。

  3. 更多令人沮丧,无助的财产尝试……


如何在合理的时间内(不是30分钟左右)配置Eureka以驱逐实例或将状态设置为DOWN不发送心跳的实例?


代码片段

服务器本身不包含可提及的代码(只需几个注释即可使用Spring Cloud Starter启动Eureka服务器)。

Eureka服务器的配置(我删除了所有非工作尝试):

 server: port: 8761 spring: cloud: client: hostname: localhost eureka: instance: address: 127.0.0.1 hostname: ${spring.cloud.client.hostname} 

发送到服务器的客户端配置(使用eureka-js-client ):

 { instance : { instanceId : `${CONFIG.instance.address}:${CONFIG.instance.name}:${CONFIG.instance.port}`, app : CONFIG.instance.name, hostName : CONFIG.instance.host, ipAddr : CONFIG.instance.address, port : { '$' : CONFIG.instance.port, '@enabled' : true }, homePageUrl : `http://${CONFIG.instance.host}:${CONFIG.instance.port}/`, statusPageUrl : `http://${CONFIG.instance.host}:${CONFIG.instance.port}/info`, healthCheckUrl : `http://${CONFIG.instance.host}:${CONFIG.instance.port}/health`, vipAddress : CONFIG.instance.name, secureVipAddress : CONFIG.instance.name, dataCenterInfo : { '@class' : 'com.netflix.appinfo.InstanceInfo$DefaultDataCenterInfo', name : 'MyOwn' } }, eureka : { host : CONFIG.eureka.host, port : CONFIG.eureka.port, servicePath : CONFIG.eureka.servicePath || '/eureka/apps/', healthCheckInterval : 5000 } } 

过了一会儿,我们有一个微服务的十个或更多个实例,其中只有一个上升,但所有都被认为是上升。

尤里卡有一种“自我保护”模式。 如果少于85%的实例心跳正在注册,则不会驱逐任何实例。 您应该能够在尤里卡仪表板上看到警告。