最近EFK遇到一個(gè)問題,就是當(dāng)集群的歷史日志過多的時(shí)候,新安裝的EFK會(huì)因?yàn)閿?shù)據(jù)太多導(dǎo)致無法把數(shù)據(jù)轉(zhuǎn)發(fā)到Elasticsearch,如果Elasticsearch內(nèi)小會(huì)出現(xiàn)內(nèi)存溢出的情況。
Fluentd會(huì)報(bào)錯(cuò):
2023-06-06 07:51:42 +0000 [warn]: #0 [elasticsearch] failed to flush the buffer. retry_time=13 next_retry_seconds=2023-06-06 07:52:11 205662141207559029589/549755813888000000000 +0000 chunk="5fd71419499cd6011cb8d9147bb6ec3c" error_class=Fluent::Plugin::ElasticsearchOutput::RecoverableRequestFailure error="could not push logs to Elasticsearch cluster ({:host=>\"elasticsearch-cluster-es-http.elastic-system.svc.cluster.local\", :port=>9200, :scheme=>\"http\", :user=>\"admin\", :password=>\"obfuscated\"}): read timeout reached" 2023-06-06 07:51:42 +0000 [warn]: #0 suppressed same stacktrace
解決方法,修改配置文件為如下:
logstash_format true reload_connections false reconnect_on_error true reload_on_failure true slow_flush_log_threshold 25.0 <buffer> @type file path /var/log/fluentd-buffers/kubernetes.system.buffer flush_mode interval flush_interval 5s flush_thread_count 4 chunk_full_threshold 0.9 retry_type exponential_backoff retry_timeout 1m retry_max_interval 30 request_timeout 15s retry_limit 5 retry_max_interval 30 retry_timeout 1m chunk_limit_size 2M total_limit_size 20M overflow_action drop_oldest_chunk </buffer>
buffer_type,緩沖類型,可以設(shè)置file或者memory
buffer_chunk_limit,每個(gè)chunk塊的大小,默認(rèn)8MB,The value for option buffer_chunk_limit should not exceed value http.max_content_length in your Elasticsearch setup (by default it is 100MB).
buffer_queue_limit ,chunk塊隊(duì)列的最大長(zhǎng)度,默認(rèn)256
flush_interval ,flush一個(gè)chunk的時(shí)間間隔
retry_limit ,chunk塊發(fā)送失敗重試次數(shù),默認(rèn)17次,之后就丟棄該chunk數(shù)據(jù)。retry_max_times 17 # Maximum retry count before giving up
retry_wait ,重試發(fā)送chunk數(shù)據(jù)的時(shí)間間隔,默認(rèn)1s,第2次失敗再發(fā)送的話,間隔2s,下次4秒,以此類推。
retry_type,exponential_backoff指數(shù)退避或periodic定期;
retry_max_interval,在retry_type設(shè)置為exponential_backoff時(shí),等待時(shí)間間隔可以限制在retry_max_interval指定范圍內(nèi)。
(Fluentd將在以下2種情況下中止傳輸失敗chunks 的嘗試:1.The number of retries exceeds retry_max_times (default: none);2.The seconds elapsed since the first retry exceeds retry_timeout(default: 72h))在這些事件中,隊(duì)列queue中的所有chunks 都將被丟棄。如果想避免這種情況,可以啟用retry_forever使Fluentd無限期重試。
drop_oldest_chunk:刪除最舊的緩沖塊以接受新傳入的緩沖塊