89

Spring Cloud整合配置中心Eureka中的服务状态显示UNKOWN

 5 years ago
source link: https://www.ydstudio.net/archives/87.html?amp%3Butm_medium=referral
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

今天在研究Spring Cloud的配置中心的时候,发现将应用的配置移到git上,启动应用后发现,在Euraka注册中心上这个应用的状态始终为UNKOWN,可是这个应用是可以提供服务的。下面是应用的bootstrap的配置:

spring:
  application:
    name: search-provider
  cloud:
    config:
      name: search-config
      profile: dev
      label: master
      discovery:
        enabled: true
        service-id: config-server
eureka:
    client:
        fetch-registry: true
        register-with-eureka: true
        healthcheck:
           enabled: true
        service-url:
          defaultZone: http://xxxx:[email protected]:xxx/eureka/
    instance:
        #instance-id默认值是主机名:应用名:应用端口 instance-id: ${spring.application.name}:${random.value}
        #instance-id: ${spring.cloud.client.ipAddress}:${server.port}
        instance-id: ${spring.cloud.client.ipAddress}:${spring.application.name}:${server.port}
        hostname: ${spring.cloud.client.ipAddress}
        #hostname: ${spring.application.name}
        # 默认30s,表示eureka client发送心跳给server端的频率
        lease-renewal-interval-in-seconds: 15
        # 默认90s,表示eureka server至上一次收到client的心跳之后,等待下一次心跳的超时时间,在这个时间内若没收到下一次心跳,则将移除该instance
        lease-expiration-duration-in-seconds: 25
        # 将自己的ip显示到EuekaServer上
        prefer-ip-address: true

日志打印应用的状态:

StatusChangeEvent [timestamp=1536481926709, current=UNKNOWN, previous=UP]

这些配置肯定没有什么问题,因为这些配置在没有挪到bootstrap.yml中之前都是可以正常使用的。现在Eureka注册中心却不能检测到应用的状态,这样让我百思不得其解。后来我在stackoverflow上找到了答案

stackoverflow地址 ,问题只有一个答案,其中重要内容如下:

eureka.client.healthcheck.enabled=true should only be set in  application.yml. Setting the value in bootstrap.yml will cause undesirable side effects like registering in eureka with an  UNKNOWN status.

知道这一点后我将bootstrap.yml中的内容修改如下面一样:

spring:
  application:
    name: search-provider
  cloud:
    config:
      name: search-config
      profile: dev
      label: master
      #uri: http://localhost:9008
      discovery:
        enabled: true
        service-id: config-server

eureka:
    client:
        fetch-registry: true
        register-with-eureka: true
        healthcheck:
           enabled: true
        service-url:
          defaultZone: http://xxxx:[email protected]:xxx/eureka/

在Eureka注册中心中应用的状态就显示正常了!

最后更新于 2018-09-09 17:40:25 并被添加「spring cloud eureka」标签,已有 3 位童鞋阅读过。


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK