一、背景
健康检测接口返回OUT_OF_SERVICE
curl -X GET http://192.168.5.53:8085/mgm/health
{"status":"OUT_OF_SERVICE"}
从日志启动看,没有任何报错信息;而且jvm进程也启动成功。
关键的一点信息是,服务的swagger地址访问也正常。
但是,consul上的服务状态就是不健康。
当然,重启大法不好使。
二、解决办法
增加配置项: management.endpoint.health.show-details: always
{
"status":"OUT_OF_SERVICE",
"components":{
"consul":{
"status":"UP",
"details":{
"leader":"192.168.5.65:8500",
"services":{
"product-service":[
"secure=false"
],
"user-service":[
"version=1.5.3",
"secure=false",
"management.context-path=/mgm",
"health.path=/health"
]
}
}
},
"discoveryComposite":{
"status":"UP",
"components":{
"discoveryClient":{
"status":"UP",
"details":{
"services":[
"product-service",
"user-service"
]
}
}
}
},
"diskSpace":{
"status":"UP",
"details":{
"total":105033031680,
"free":68411322368,
"threshold":10485760
}
},
"elasticsearchRest":{
"status":"OUT_OF_SERVICE",
"details":{
"cluster_name":"test-cluster",
"status":"red",
"timed_out":false,
"number_of_nodes":1,
"number_of_data_nodes":1,
"active_primary_shards":93,
"active_shards":93,
"relocating_shards":0,
"initializing_shards":0,
"unassigned_shards":16,
"delayed_unassigned_shards":0,
"number_of_pending_tasks":0,
"number_of_in_flight_fetch":0,
"task_max_waiting_in_queue_millis":0,
"active_shards_percent_as_number":85.3211009174312
}
},
"hystrix":{
"status":"UP"
},
"mongo":{
"status":"UP",
"details":{
"version":"4.0.27"
}
},
"nacosConfig":{
"status":"UP"
},
"ping":{
"status":"UP"
},
"rabbit":{
"status":"UP",
"components":{
"globalRabbitTemplate":{
"status":"UP",
"details":{
"version":"3.6.6"
}
},
"rabbitTemplate":{
"status":"UP",
"details":{
"version":"3.6.6"
}
}
}
},
"redis":{
"status":"UP",
"details":{
"version":"3.2.11"
}
},
"refreshScope":{
"status":"UP"
}
}
}
-
可以看出,elasticsearchRest的状态是OUT_OF_SERVICE。
-
经排查,原来是配置项误写成了测试环境的es地址
- 测试环境:http://192.168.10.147:9200
- 开发环境:http://192.168.5.71:9200
修改es的地址未开发环境的地址, spring.elasticsearch.rest.uris
三、检验
- consul上的服务状态变成了健康,服务可用。
- 服务本身的健康检测返回:{“status”:“UP”}