测试 spring cloud 使用 consul 注册服务的时候,出现 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 这个端点不能使用,加上这个包,问题就解决了。