代码之家  ›  专栏  ›  技术社区  ›  user674669

为什么领事健康检查返回空数组?

  •  1
  • user674669  · 技术社区  · 8 年前

    我们有一个码头工人。yml文件:

    version: '3'
    services:
      consul:
        container_name: consul
        command: agent -dev -config-dir=/consul/config
        dns: 8.8.8.8
        hostname: consul-docker
        image: docker-registry.mycompany.net/ap/consul-ent:0.9.2
        ports:
          - "8500:8500"
        volumes:
          - ./consul/config/conf.json:/consul/config/conf.json
    
    # https://github.com/gliderlabs/registrator
      registrator:
        command: consul://consul:8500
        container_name: registrator
        depends_on:
          - consul
        image: gliderlabs/registrator:latest
        restart: always
        volumes:
          - /var/run/docker.sock:/tmp/docker.sock
    
      myservice1:
        container_name: myservice1
        image: docker-registry.mycompany.net/ap/myservice1/develop:latest
        ports:
          - "8080:8080"
          - "5000:5000"
    
    # more services below
    

    当我使用Consor v1 API检查运行状况时,请转到 http://localhost:8500/v1/health/checks/myservice1 ,它返回一个空数组[]。 enter image description here

    根据docker ps和myservice1的日志,myservice1已经准备好了。

    myservice1显示绿色 http://localhost:8500/ui/#/dc1/services

    myservice1是一个基于dropwizard的java微服务。

    根据 https://www.consul.io/api/health.html ,样本响应

    $ curl https://consul.rocks/v1/health/service/my-service
    

    看起来像:

    [
      {
        "Node": {
          "ID": "40e4a748-2192-161a-0510-9bf59fe950b5",
          "Node": "foobar",
          "Address": "10.1.10.12",
          "Datacenter": "dc1",
          "TaggedAddresses": {
            "lan": "10.1.10.12",
            "wan": "10.1.10.12"
          },
          "Meta": {
            "instance_type": "t2.medium"
          }
        },
        "Service": {
          "ID": "redis",
          "Service": "redis",
          "Tags": ["primary"],
          "Address": "10.1.10.12",
          "Port": 8000
        },
        "Checks": [
          {
            "Node": "foobar",
            "CheckID": "service:redis",
            "Name": "Service 'redis' check",
            "Status": "passing",
            "Notes": "",
            "Output": "",
            "ServiceID": "redis",
            "ServiceName": "redis",
            "ServiceTags": ["primary"]
          },
          {
            "Node": "foobar",
            "CheckID": "serfHealth",
            "Name": "Serf Health Status",
            "Status": "passing",
            "Notes": "",
            "Output": "",
            "ServiceID": "",
            "ServiceName": "",
            "ServiceTags": []
          }
        ]
      }
    ]
    

    根据注册者日志,它看到myservice1很好,并添加了myservice1。

    如果您能告诉我为什么会有[]的回复,我们将不胜感激?

    1 回复  |  直到 8 年前
        1
  •  0
  •   user674669    8 年前

    在遵循以下说明后,我能够进行基本的健康检查: https://gliderlabs.com/registrator/latest/user/backends/ . 我的印象是,设置注册人和领事后,健康检查将自动工作。我需要通过在docker compose中提供环境变量来设置HTTP检查。yml类:

    SERVICE_80_CHECK_HTTP=/health/endpoint/path
    SERVICE_80_CHECK_INTERVAL=15s
    SERVICE_80_CHECK_TIMEOUT=1s     # optional, Consul default used otherwise
    
    推荐文章