记录consul注册服务的错误

1、consul启动到管理页面时,出现一个Service Checks = false

这个是由于actuator/health无法检测,因为项目中的consul需要检测服务的健康状态。

可以使用 http://localhost:8500/v1/agent/checks 查看你的consul中各个服务的情况,直接定位到带错误的服务就可以。

我是直接指定spring.cloud.consul.discovery.health-check-url

属性为:http://${spring.cloud.consul.host}:${server.port}/actuator/health

${spring.cloud.consul.host} =》获取当前consul的主机ip,就是你配置的

${server.port} =》当前服务的端口

server:
  port: 8006

spring:
  application:
    name: consul-payment-service
  cloud:
    consul:
      host: 127.0.0.1
      port: 8500
      discovery:
        health-check-url: http://${spring.cloud.consul.host}:${server.port}/actuator/health
        service-name: ${spring.application.name}

2、通过服务提供者的服务id访问不到报No instances  avalable for   服务名称

我添加了以下配置(网友的解释是,consul默认用hostname注册,不会用ip)

enabled: true
# 使用 consul 服务器 IP, 而不是 hostname, 需要搭配 prefer-ip-address 属性
ip-address: 127.0.0.1
# 在注册时使用 consul IP, 而不是 hostname
prefer-ip-address: true
server:
  port: 80

spring:
  application:
    name: consul-order-service
  cloud:
    consul:
      host: 127.0.0.1
      port: 8500
      discovery:
        enabled: true
        # 使用 consul 服务器 IP, 而不是 hostname, 需要搭配 prefer-ip-address 属性
        ip-address: 127.0.0.1
        # 在注册时使用 consul IP, 而不是 hostname
        prefer-ip-address: true
        health-check-url: http://${spring.cloud.consul.host}:${server.port}/actuator/health
        service-name: ${spring.application.name}

参考文章:https://blog.csdn.net/u010173095/article/details/88568751

 

你可能感兴趣的:(springcloud,#consul)