1.确认项目的pom依赖存在以下两项:
<dependency> <groupId>de.codecentric</groupId> <artifactId>spring-boot-admin-starter-client</artifactId> <version>2.0.5</version> </dependency>
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-actuator</artifactId> </dependency>
2.application.yml文件里相关配置添加以下项目,注意对齐:
management: server: # 监控管理端口 port: 你的端口 endpoints: web: exposure: # 需要开放的 Actuator 监控端点,默认开放所有 include: '*' health: sensitive: false endpoint: health: # 重要,排查问题必备,如果没有下面这项,访问/actuator/health时只会告诉你服务状态为down show-details: ALWAYS
3.重启服务,访问 服务ip:服务端口/actuator/health,查看返回信息中所有信息的status是否均为up
例:
{"status":"UP","details":{"diskSpace":{"status":"UP","details":{"total":510745636864,"free":140418973696,"threshold":10485760}},"refreshScope":{"status":"UP"},"discoveryComposite":{"status":"UP","details":{"discoveryClient":{"status":"UP","details":{"services":["hzero-admin","hzero-config","hzero-todo-service"]}},"eureka":{"description":"Eureka discovery client has not yet successfully connected to a Eureka server","status":"UP","details":{"applications":{"HZERO-ADMIN":1,"HZERO-CONFIG":1,"HZERO-TODO-SERVICE":1}}}}},"hystrix":{"status":"UP"}}}
上图所示,当所有status均为up,服务状态为up。若某一项为down则服务状态为down。
现在把配置文件中的redis密码修改成错误的密码再重新启动,如下:
{"status":"DOWN","details":{"diskSpace":{"status":"UP","details":{"total":510745636864,"free":140385398784,"threshold":10485760}},"refreshScope":{"status":"UP"},"discoveryComposite":{"status":"UP","details":{"discoveryClient":{"status":"UP","details":{"services":["hzero-admin","hzero-config"]}},"eureka":{"description":"Eureka discovery client has not yet successfully connected to a Eureka server","status":"UP","details":{"applications":{"HZERO-ADMIN":1,"HZERO-CONFIG":1}}}}},"hystrix":{"status":"UP"},"redis":{"status":"DOWN","details":{"error":"org.springframework.data.redis.RedisSystemException: Error in execution; nested exception is io.lettuce.core.RedisCommandExecutionException: NOAUTH Authentication required."}}}}
如上所示,访问/actuator/health后发现服务状态为down,并且只有redis的status变为down,原因为没有在配置文件中配置正确的认证信息,根据错误详情修改配置文件后服务又成功恢复。