4

我们正在尝试在GCP 计算引擎上向consul注册一个spring-cloud-consul应用程序,它可以向 consul 注册应用程序,但是我们面临两个应用程序问题。下面是应用程序的server.yamlbootstrap.yaml

application.yaml

server:
  port: 10003
spring:
  application:
    name: hello-service
  cloud:
    consul:
      enabled: true
    inetutils:
      useOnlySiteLocalInterfaces: true
  endpoints:
    actuator:
      sensitive: false

bootstrap.yaml

spring:
  cloud:
    consul:
      enabled: true
      host: 10.160.0.18
      port: 8500
      discovery:
        prefer-ip-address: true
  1. Consul 无法在计算引擎上调用健康检查,可能是因为它注册在实例的内部域名上。

带领事的服务:NewService{id='hello-service-10003', name='hello-service', tags=[secure=false], address='consul-app-test.c.name-of-project.internal ', meta=null, port=10003, enableTagOverride=null, check=Check{script='null', interval='10s', ttl='null', http=' http://consul-app-test.c .name-of-project.internal:10003/actuator/health ', method='null', header={}, tcp='null', timeout='null', deregisterCriticalServiceAfter='null', tlsSkipVerify=null, status ='null'},检查=null}

  1. 申请,而不是从领事处注销。我们已经停止了应用程序,它仍然显示在 consul UI 上。
4

2 回答 2

2

我对对我有用的application.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 

引导程序.yaml

spring:
  cloud:
    consul:
      enabled: true
      host: 10.160.0.18
      port: 8500
于 2019-03-02T12:54:41.433 回答
0

如果你2.1.2像我一样使用版本:org.springframework.cloud:spring-cloud-starter-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分钟后,删除服务

您可以在以下位置查看源代码ConsulDiscoveryProperties

@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;
……
于 2019-10-17T09:26:12.960 回答