最近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:删除最旧的缓冲块以接受新传入的缓冲块