spring cloud consul注册的服务有报错 critical

在测试Spring Cloud使用Consul注册服务时遇到critical错误,表现为health check失败。通过调用Consul的API发现,Consul尝试访问服务的http://xxx.xx.xxx.xxx:19008/actuator/health接口但返回404。问题根源在于服务未配置spring cloud actuator,添加相应依赖并配置后,问题得到解决。环境为:spring cloud Finchley.SR2和consul v1.4.3。

测试spring cloud 使用consul注册服务的时候,出现critical,如下:
critical

怎么解决这个问题,现在只能看到health check检查失败了。

首先调用这个请求Get http://consulIp:8500/v1/agent/checks,调完请求,就会拿到返回数据:

{
    ......
    "service:test-service-xx-xx-xx-xx": {
        "Node": "zookeeper-server1",
        "CheckID": "service:test-service-xx-xx-xx-xx",
        "Name": "Service 'test-service' check",
        "Status": "critical",
        "Notes": "",
        "Output": "HTTP GET http://xxx.xx.xxx.xxx:19008/actuator/health: 404  Output: <html><body><h1>Whitelabel Error Page</h1><p>This application has no explicit mapping for /error, so you are seeing this as a fallback.</p><div id='created'>Fri Mar 15 11:03:30 CST 2019</div><div>There was an unexpected error (type=Not Found, status=404).</div><div>No message available</div></body></html>",
        "ServiceID": "test-service-xx-xx-xx-xx",
        "ServiceName": "test-service",
        "ServiceTags": [
            "version=1.0",
            "secure=false"
        ],
        "Definition": {},
        "CreateIndex": 0,
        "ModifyIndex": 0
    }
    
    ........
}

就能看到consul调用http://xxx.xx.xxx.xxx:19008/actuator/health来检查servoce健康,却发现接口404,所以才会在页面出现错误。

我的测试环境是:

  • spring cloud Finch1ey.SR2
  • consul v1.4.3

bootstrap.yml配置是:

spring:
  cloud:
    consul:
      host: xxx.xxx.xxx.xxx
      port: 8500
      discovery:
        prefer-ip-address: true
        tags: version=1.0
        instance-id: ${spring.application.name}:${spring.cloud.client.ip-address}
        healthCheckInterval: 15s
        health-check-url: http://${spring.cloud.client.ip-address}:${server.port}/actuator/health

显然consul不能在这个服务上找到actuator/health接口,因为我用了actuator,所以service中应该配置了spring cloud actuator。

经过检查发现没有配置,所以actuator这个端点不能使用,加上这个包,问题就解决了。

评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值