在 CentOS 上运行 Filebeat 时,调优主要从系统层、Filebeat 配置、资源限制、采集策略几个方面入手。下面给你一套比较实用的调优思路和参数示例。
Filebeat 会同时监听大量日志文件,容易遇到 too many open files。
# 查看当前限制
ulimit -n
# 修改 /etc/security/limits.conf
* soft nofile 65535
* hard nofile 65535
重启会话或 Filebeat 生效。
# 提高网络吞吐
sysctl -w net.core.somaxconn=1024
sysctl -w net.ipv4.tcp_max_syn_backlog=8192
配置文件一般在:
/etc/filebeat/filebeat.yml
filebeat.inputs:
- type: log
paths:
- /var/log/*.log
scan_frequency: 10s # 默认10s,日志量大可降到1s
输出调优(以 Elasticsearch / Logstash 为例):
output.elasticsearch:
hosts: ["http://es:9200"]
worker: 4 # 并发 worker
bulk_max_size: 2048 # 每批最大事件数
flush_interval: 1s
或 Logstash:
output.logstash:
hosts: ["logstash:5044"]
worker: 4
bulk_max_size: 2048
compression_level: 3
queue.mem:
events: 4096
flush.min_events: 1024
flush.timeout: 1s
queue.disk:
path: /var/lib/filebeat/diskqueue
max_size: 10GB
processors:
- drop_fields:
fields: ["agent.ephemeral_id", "ecs.version"]
- add_host_metadata: ~
关闭不必要的 processor,减少 CPU 消耗。
❌ 不推荐:
/var/log/**
✅ 推荐:
/var/log/nginx/*.log
/var/log/app/*.log
ignore_older: 24h
close_inactive: 5m
close_renamed: true
clean_removed: true
systemctl edit filebeat
[Service]
LimitNOFILE=65535
MemoryLimit=1G
CPUQuota=200%
monitoring.enabled: true
monitoring.elasticsearch:
hosts: ["http://es:9200"]
filebeat.inputs:
- type: log
paths:
- /var/log/app/*.log
ignore_older: 12h
close_inactive: 5m
queue.disk:
path: /var/lib/filebeat/diskqueue
max_size: 5GB
output.logstash:
hosts: ["logstash:5044"]
worker: 4
bulk_max_size: 2048
processors:
- add_host_metadata: ~
如果你愿意,可以告诉我:
我可以直接帮你出一份针对你场景的 filebeat.yml 调优模板。