[英]PUT Elasticsearch Ingest Pipeline by default
我们目前使用Elasticsearch存储由Filebeat发送的Spring Boot App日志,并使用Kibana对其进行可视化。
我们的整个架构都在docker-compose文件中进行了docker化。 当前,当我们启动堆栈时,我们必须等待Elasticsearch启动,然后放置我们的Ingest Pipeline,然后重新启动Filebeat,然后才可以将我们的日志正确显示在Kibana中。
我对此很陌生,但是我想知道是否没有办法让Elasticsearch保存摄取管道,从而您不必每次都加载它们? 我读到有关准备就绪时挂载卷或运行自定义脚本以等待ES和PUT的信息,但是对于用例来说,所有这些似乎都很麻烦,在我看来,这是默认用例?
我建议使用startscript到filebeat容器中。
创建此管道并启动filebeat之后,该脚本将ping elasticsearch就绪。
#!/usr/bin/env bash -e
START_FILE=/tmp/.es_start_file
http () {
local path="${1}"
curl -XGET -s -k --fail http://${ELASTICSEARCH_HOST}:{$ELASTICSEARCH_PORT}${path}
}
pipeline() {
curl -XPUT -s -k --fail http://${ELASTICSEARCH_HOST}:{$ELASTICSEARCH_PORT}/_ingest/pipeline/$PIPELINE_NAME -d @pipeline.json
}
while true; do
if [ -f "${START_FILE}" ]; then
pipeline
/usr/bin/filebeat -c filebeat.yaml &
exit 0
else
echo 'Waiting for elasticsearch cluster to become green'
if http "/_cluster/health?wait_for_status=green&timeout=1s" ; then
touch ${START_FILE}
fi
fi
done
此方法对于docker-compose和docker swarm来说是很好的。 对于k8,最好创建准备就绪探针。
通过在自定义Elasticsearch图像的构建过程中运行脚本,我们使用了与ozlevka类似的方法。
这是我们的脚本:
#!/bin/bash
# This script sets up the Elasticsearch docker instance with the correct pipelines and templates
baseUrl='localhost:9200'
contentType='Content-Type:application/json'
# filebeat
ingestUrl=$baseUrl'/_ingest/pipeline/our-pipeline?pretty'
payload='/usr/share/elasticsearch/config/our-pipeline.json'
/usr/share/elasticsearch/bin/elasticsearch -p /tmp/pid > /dev/null &
# wait until Elasticsearch is up
# you can get logs if you change /dev/null to /dev/stderr
while [[ "$(curl -s -o /dev/null -w ''%{http_code}'' -XPUT $ingestUrl -H$contentType -d@$payload)" != "200" ]]; do
echo "Waiting for Elasticsearch to start and posting pipeline..."
sleep 5
done
kill -SIGTERM $(cat /tmp/pid)
rm /tmp/pid
echo -e "\n\n\nCompleted Elasticsearch Setup, refer to logs for details"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.