將資料傳送至 Elasticsearch 時, Logstash 報告錯誤

Logstash 已配置為將大量資料傳送至 Elasticsearch,但在傳送大量資料時失敗,並在 Logstash 中收到類似下列的錯誤訊息:

[2021-05-24T15:50:22,049][ERROR][logstash.outputs.elasticsearch][esarchive][72e046782ee7ecdaeef95d897e7dc9fd30f75e2dd3e0273fd878fabac23b9e79] Encountered a retryable error. Will Retry with exponential backoff {:code=>502, :url=>"https://iaf-system-elasticsearch-es.optest:9200/_bulk", :content_length=>362194, :body=>"\r\n<title>502 Bad Gateway</title>\r\n\r\n

502 Bad Gateway
\r\n
nginx\r\n\r\n\r\n"}The requested API: <API> with method GET: is not listed in the Allow List.

Elasticsearch tls-proxy 儲存器也會產生錯誤,如下所示:

iaf-system-elasticsearch-es-master-data-0 tls-proxy 2021/05/24 15:36:30 [error] 11#0: *1483 upstream sent too big header while reading response header from upstream, client: 10.254.17.31, server: tls-proxy-9200, request: "POST /_bulk HTTP/1.1", upstream: "http://127.0.0.1:9201/_bulk", host: "iaf-system-elasticsearch-es.optest:9200"

原因

發生此錯誤的原因是作為 /_bulk request 的一部分傳送至 Elasticsearch 的標頭資料大小,且 tls-proxy 儲存器無法處理它,這會導致要求失敗。

解決問題

若要解決此問題,您需要在 Logstash 配置中限制每個批次 (用於 Elasticsearch 大量查詢) 的資料大小。 以下是配置設定的範例:

pipeline.batch.size: 35
pipeline.batch.delay: 10

附註: 用於這些設定的值視正在傳送且需要調整的資料大小而定。