Spring boot Spring Cloud领事健康检查和GCP上的状态配置

Spring boot Spring Cloud领事健康检查和GCP上的状态配置,spring-boot,google-cloud-platform,spring-cloud-consul,Spring Boot,Google Cloud Platform,Spring Cloud Consul,我们正在尝试向on注册申请,它可以向领事注册申请,但我们在申请中面临两个问题。下面是应用程序的引导.yaml和服务器.yaml 应用程序.yaml server: port: 10003 spring: application: name: hello-service cloud: consul: enabled: true inetutils: useOnlySiteLocalInterfaces: true endpoints:

我们正在尝试向on注册申请,它可以向领事注册申请,但我们在申请中面临两个问题。下面是应用程序的
引导.yaml
服务器.yaml

应用程序.yaml

server:
  port: 10003
spring:
  application:
    name: hello-service
  cloud:
    consul:
      enabled: true
    inetutils:
      useOnlySiteLocalInterfaces: true
  endpoints:
    actuator:
      sensitive: false
spring:
  cloud:
    consul:
      enabled: true
      host: 10.160.0.18
      port: 8500
      discovery:
        prefer-ip-address: true
bootstrap.yaml

server:
  port: 10003
spring:
  application:
    name: hello-service
  cloud:
    consul:
      enabled: true
    inetutils:
      useOnlySiteLocalInterfaces: true
  endpoints:
    actuator:
      sensitive: false
spring:
  cloud:
    consul:
      enabled: true
      host: 10.160.0.18
      port: 8500
      discovery:
        prefer-ip-address: true
  • 领事无法调用计算引擎上的运行状况检查,可能是因为它已在实例的内部域名上注册 领事服务:NewService{id='hello-service-10003', name='hello-service',tags=[secure=false], 地址='concur-app-test.c.name-of-project.internal',meta=null, port=10003,enableTagOverride=null,check=check{script='null', 间隔时间=10s',ttl='null', http=“”, 方法='null',头={},tcp='null',超时='null', 撤销注册CriticalServiceAfter='null',tlsSkipVerify=null, status='null'},checks=null}

  • 申请,而不是从领事处注销。我们已经停止了应用程序,但它仍显示在Consour UI上

  • 我在应用程序.yamlbootstrap.yaml中做了一些更改,这对我很有用

    应用程序.yaml

    spring:
      application:
        name: hello-service
      cloud:
        consul:
          discovery:
            instanceId: ${spring.application.name}:${random.value}
            health-check-critical-timeout: 3m
            prefer-ip-address: true # disable if we want to use google cloud internal DNS 
    
    spring:
      cloud:
        consul:
          enabled: true
          host: 10.160.0.18
          port: 8500
    
    bootstrap.yaml

    spring:
      application:
        name: hello-service
      cloud:
        consul:
          discovery:
            instanceId: ${spring.application.name}:${random.value}
            health-check-critical-timeout: 3m
            prefer-ip-address: true # disable if we want to use google cloud internal DNS 
    
    spring:
      cloud:
        consul:
          enabled: true
          host: 10.160.0.18
          port: 8500
    

    如果您像我一样使用版本
    2.1.2
    :org.springframework.cloud:springcloudstarter consul discovery:2.1.2.RELEASE

    您可以设置:

    spring:
    
      cloud:
        consul:
          host: localhost #  consul的地址
          port: 8500 # consul 的端口
          discovery:
            prefer-ip-address: true  # // This must be matched
            tags: version=1.0
            instance-id: ${spring.application.name}:${spring.cloud.client.ip-address}
            healthCheckPath: /actuator/health # 服务做健康检查的端口
            healthCheckInterval: 15s  # 服务健康检查的周期
            healthCheckTimeout: 60s # 服务检查是的timeout时长
            healthCheckCriticalTimeout: 5m # 服务健康检查失败5分钟后,删除服务
    
    您可以在
    ConsultDiscoveryProperties
    中查看源代码:

    @ConfigurationProperties("spring.cloud.consul.discovery")
    public class ConsulDiscoveryProperties {
    
    ……
    
        /** Is service discovery enabled? */
        private boolean enabled = true;
    
        /** Alternate server path to invoke for health checking. */
        private String healthCheckPath = "/actuator/health";
    
        /** Custom health check url to override default. */
        private String healthCheckUrl;
    
        /** How often to perform the health check (e.g. 10s), defaults to 10s. */
        private String healthCheckInterval = "10s";
    
        /** Timeout for health check (e.g. 10s). */
        private String healthCheckTimeout;
    
        /**
         * Timeout to deregister services critical for longer than timeout (e.g. 30m).
         * Requires consul version 7.x or higher.
         */
        private String healthCheckCriticalTimeout;
    ……