在Debian系统中,Filebeat日志压缩可通过以下两种方式实现:
sudo apt-get install logrotate
/etc/logrotate.d/目录下创建filebeat配置文件,添加以下内容:/var/log/filebeat/*.log {
daily
rotate 7
compress
delaycompress
missingok
notifempty
create 640 root adm
postrotate
/usr/bin/filebeat -f /etc/filebeat/filebeat.yml reload > /dev/null
endscript
}
compress:启用压缩(默认使用gzip)。delaycompress:延迟压缩,直到下一次轮转。sudo logrotate -f /etc/logrotate.d/filebeat # 手动测试
logrotate默认通过cron每日自动运行。/etc/filebeat/filebeat.yml中,为输入模块添加compress处理器:filebeat.inputs:
- type: log
paths: ["/var/log/filebeat/*.log"]
processors:
- compress:
codec: gzip # 压缩编解码器(支持gzip、zstd等)
sudo systemctl restart filebeat
注意:此方式仅在日志传输到输出目标(如Elasticsearch)前压缩,不会压缩本地日志文件。
/var/log/filebeat/),配置compress和rotate参数。processors再次启用压缩,减少网络传输量。以上配置可根据实际需求调整压缩频率、保留天数等参数,确保日志管理高效且节省存储空间。