spring cloud consul註冊的服務報錯critical的解決

這篇文章主要介紹了spring cloud consul註冊的服務報錯critical的解決,小編覺得挺不錯的,現在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧

測試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這個端點不能使用,加上這個包,問題就解決了。

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持神馬文庫。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章