在 CentOS 上运行 Filebeat 时,如果目的是节省系统资源(CPU、内存、磁盘 IO、网络),可以从配置优化、运行方式、系统层面几个方向来做。下面按实用性整理。
filebeat.inputs:
- type: log
paths:
- /var/log/nginx/*.log
# 不要采集整个目录树
❌ 避免:
paths:
- /var/log/**
scan_frequency: 30s # 默认10s,可调大
文件少、变更不频繁时可设为 60s。
max_procs: 1
或限制并发文件读取:
harvester_limit: 5
queue.mem:
events: 1024 # 默认4096
maxbytes: 10mb
使用 filebeat 内置队列(不接 Kafka / Redis 时):
queue.type: persisted
queue.max_bytes: 50mb
output.elasticsearch:
hosts: ["http://es:9200"]
bulk_max_size: 100 # 默认50
flush_interval: 10s # 默认1s
filebeat modules disable system
filebeat modules disable nginx
只保留你真正用的。
processors:
- drop_fields:
fields: ["agent", "ecs", "host"]
或:
processors:
- add_host_metadata: ~
- add_cloud_metadata: ~
如果不用,直接删掉。
systemctl edit filebeat
添加:
[Service]
CPUQuota=20%
MemoryMax=200M
然后:
systemctl daemon-reload
systemctl restart filebeat
nice -n 10 filebeat -c filebeat.yml
或修改 systemd:
Nice=10
filebeat.inputs:
- type: log
paths:
- /var/log/app/*.log
ignore_older: 24h
避免启动后“回扫”大量旧日志。
Filebeat 对磁盘 IO 不敏感,但 registry 文件频繁写。
filebeat.registry.path: /dev/shm/filebeat
⚠️ 重启会丢失采集位置(不推荐生产)
本地文件 > Redis/Kafka > Logstash > Elasticsearch
如果 ES 压力大:
systemctl status filebeat
top -p $(pidof filebeat)
或开启监控:
monitoring.enabled: true
filebeat.inputs:
- type: log
paths:
- /var/log/app/*.log
ignore_older: 12h
scan_frequency: 30s
harvester_limit: 3
max_procs: 1
queue.mem:
events: 1024
maxbytes: 10mb
output.elasticsearch:
hosts: ["http://es:9200"]
bulk_max_size: 100
flush_interval: 10s
processors:
- drop_fields:
fields: ["agent", "ecs"]
如果你愿意,可以告诉我:
我可以给你一份直接可用的配置。