最近EFK遇到一個問題,就是當集群的歷史日志過多的時候,新安裝的EFK會因為數據太多導致無法把數據轉發到Elasticsearch,如果Elasticsearch內小會出現內存溢出的情況。
Fluentd會報錯:
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,緩沖類型,可以設置file或者memory
buffer_chunk_limit,每個chunk塊的大小,默認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塊隊列的最大長度,默認256
flush_interval ,flush一個chunk的時間間隔
retry_limit ,chunk塊發送失敗重試次數,默認17次,之后就丟棄該chunk數據。retry_max_times 17 # Maximum retry count before giving up
retry_wait ,重試發送chunk數據的時間間隔,默認1s,第2次失敗再發送的話,間隔2s,下次4秒,以此類推。
retry_type,exponential_backoff指數退避或periodic定期;
retry_max_interval,在retry_type設置為exponential_backoff時,等待時間間隔可以限制在retry_max_interval指定范圍內。
(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))在這些事件中,隊列queue中的所有chunks 都將被丟棄。如果想避免這種情況,可以啟用retry_forever使Fluentd無限期重試。
drop_oldest_chunk:刪除最舊的緩沖塊以接受新傳入的緩沖塊