如何在同一主机上的服务的consul容器中定义HTTP运行状况检查?

 壹诺彡_壹生 发布于 2022-12-04 02:04

我们在也运行服务的主机上使用了一个consul代理.(RabbitMQ)为了验证服务是否准备就绪,我们已经定义了基于卷曲的运行状况检查.但是,我们使用registrator使用env变量注入此检查.SERVICE_CHECK_SCRIPT =卷曲hostname:15672/....

问题是,我们还告诉consul-agent其主机名与主机相同.(我们必须拥有此功能,因为我们希望看到向consul集群注册的正确主机名.

当consul代理运行运行状况检查时,它会在自己的容器中查找URL ...这显然会失败...是否有人知道如何定义此运行状况检查(我们使用mesos来执行此操作)以便curl将尝试连接到正确的IP?

1 个回答
  • 您可以使用Registrator的HTTP运行状况检查(前提是您在progrium/docker-consul容器内运行Consul ),例如:

    ENV SERVICE_CHECK_HTTP=/howareyou
    ENV SERVICE_CHECK_INTERVAL=5s
    

    此检查将运行由提供的check-http脚本docker-consul,该脚本使用Docker API 解析目标容器的IP和端口.

    The other option is to configure Consul DNS to listen on Docker's bridge IP (which is already done in progrium/docker-consul's run script), and launch Docker daemon with the global DNS option pointing to the same IP, e.g. docker -d --bip 10.0.42.1/24 --dns 10.0.42.1 --dns 8.8.8.8.

    After that Consul DNS will be available in any of your containers, including the docker-consul one, which means that you can run curl http://my-app.service.consul:12345/howareyou, or even query SRV records, e.g. with dig -t SRV, to obtain both IP and port of a service. And then you may add 10.0.42.1 to the host's resolv.conf to gain the ability to query Consul DNS not only within containers, but from the host OS too.

    The preferred method, imho, is to use Registrator's SERVICE_CHECK_HTTP, but setting up Consul DNS for your containers is worth doing anyway.

    Both these methods require running Consul agent in client mode on each of your application hosts, but Consul agent, when ran in this mode, uses such a tiny amount of system resources that you'll hardly notice it. And you need it anyway to perform health checks :)

    2022-12-11 02:12 回答
撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有