docker - docker-compose 上的 ElasticSearch Healthcheck 失败
问题描述
docker-compose 上的 Elasticsearch 健康检查会停止任何依赖服务,因为容器总是不健康的。我跑的时候看到这个docker ps -a --format "table {{.Names}}\t{{.Image}}\t{{.Status}}"
NAMES IMAGE STATUS
elasticsearch elasticsearch:7.12.1 Up 26 seconds (unhealthy)
我正在尝试启动 metricbeat,以便启动 elasticsearch、kibana 和 logstash:
metricbeat:
image: elastic/metricbeat:7.12.1
user: root
depends_on:
elasticsearch:
condition: service_healthy
kibana:
condition: service_healthy
logstash:
condition: service_healthy
redis:
condition: service_healthy
如何确保弹性搜索(和其他容器是健康的)并允许 metricbeat 从所有可用资源开始?
除非绝对需要,否则我会避免为其中任何一个创建 Docker 映像。
我的 docker-compose 配置如下所示:
version: '3.7'
services:
elasticsearch:
# specifying discovery.type='single-node' bypasses bootstrapping checks.
image: elasticsearch:7.12.1
container_name: elasticsearch
healthcheck:
test: [ "CMD", "curl", "--fail" , "http://elasticsearch:9200/_cluster/health?wait_for_status=green&timeout=1s", "||", "exit", "1" ]
interval: 5s
timeout: 3s
volumes:
- elasticsearch-data:/usr/share/elasticsearch/data
networks:
- elastic
ports:
- 9200:9200
- 9300:9300
labels:
co.elastic.metrics/module: "elasticsearch"
co.elastic.metrics/hosts: "http://elasticsearch:9200"
co.elastic.metrics/metricsets: "node_stats,node"
co.elastic.metrics/xpack.enabled: "true"
environment:
- node.name=elasticsearch
- cluster.name=cluster-7
- discovery.type=single-node
- 'ES_JAVA_OPTS=-Xms512m -Xmx512m'
- xpack.monitoring.enabled=true
- xpack.monitoring.elasticsearch.collection.enabled=true
ulimits:
memlock:
soft: -1
hard: -1
nofile:
soft: 65536
hard: 65536
cap_add:
- IPC_LOCK
解决方案
该方法可能因弹性版本而异。此外,如果您使用 OpenSearch,您还需要使用其他东西,它们的健康输出略有不同(但仅供参考)
我正在添加我在 docker-compose 中使用的内容
healthcheck:
interval: 10s
retries: 80
test: curl --write-out 'HTTP %{http_code}' --fail --silent --output /dev/null http://localhost:8200/
或者
healthcheck:
test: curl -s http://elasticsearch01:9200 >/dev/null || exit 1
interval: 30s
timeout: 10s
retries: 50
推荐阅读
- c# - Blazor “@ref” 指循环命令中的最后一个元素
- amazon-web-services - 内网弹性ip dns更新慢
- python - 工作表的路径正确,但条形图未添加到工作表中
- ruby-on-rails - 比较具有相同索引器但值不同的 2 个不同数组
- mysql - Sql查询以查找按ID排序和分组
- ios - iOS Framework 升级到 Swift 4.2 导出太浪费空间
- javascript - 我的 chartJS axios.get 被触发了两次,导致图表也渲染了两次,我不知道为什么。我正在使用 react-chartjs-2
- cvs2git - cvs2git 在将 CVS 迁移到 Git 时创建了一些额外的提交
- mongodb - 将 vert.x 异步 mongo 客户端与 spring data mongodb 一起使用
- ruby-on-rails - 如何记住复选框状态Rails?