默认情况下,PUT Elasticsearch Ingest Pipeline

问题描述 投票:0回答:2

我们目前使用Elasticsearch存储由Filebeat发送的Spring Boot App日志,并使用Kibana来可视化。

我们的整个架构都停靠在docker-compose文件中。目前,当我们启动堆栈时,我们必须等待Elasticsearch启动,然后PUT我们的Ingest Pipeline,然后重新启动Filebeat,然后才能在Kibana中正确显示我们的日志。

我对此很陌生,但我想知道是否没有办法让Elasticsearch保存摄取管道,这样你就不必每次都加载它们?我读到了关于安装卷或运行自定义脚本以便在准备好时等待ES和PUT,但对于一个对我来说似乎是默认情况的用例来说,所有这些看起来都非常麻烦?

docker elasticsearch logging kibana filebeat
2个回答
0
投票

我建议将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。对于k8s,最好创建就绪探针。


0
投票

我们通过在自定义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"
© www.soinside.com 2019 - 2024. All rights reserved.