在Debian上设置Filebeat的日志轮转可以通过两种主要方式实现:使用logrotate工具或通过Filebeat自身的配置。以下是详细的设置步骤:
sudo apt-get install logrotate
创建或编辑logrotate配置文件:
在/etc/logrotate.d/
目录下创建或编辑Filebeat的配置文件,例如filebeat
。
sudo nano /etc/logrotate.d/filebeat
添加以下内容到配置文件:
/var/log/filebeat/*.log {
rotate 7
daily
missingok
notifempty
compress
delaycompress
sharedscripts
postrotate
/usr/bin/filebeat -e
endscript
}
这个配置表示每天轮转一次/var/log/filebeat/
目录下的所有.log
文件,保留最近7个日志文件,并对旧的日志文件进行压缩。
测试logrotate配置:
sudo logrotate -f /etc/logrotate.d/filebeat
/etc/cron.daily/logrotate
文件来确认logrotate的定时任务设置。sudo vim /etc/filebeat/filebeat.yml
filebeat.inputs:
- type: log
paths:
- /var/log/filebeat/*.log
output.file:
path: "/var/log/filebeat/filebeat.log"
filename: "filebeat.log"
max_size: 100MB
max_files: 5
这个配置表示Filebeat将日志输出到/var/log/filebeat/filebeat.log
文件,每个文件最大大小为100MB,最多保留5个文件。
sudo systemctl restart filebeat
通过以上步骤,你可以在Debian上为Filebeat设置日志轮转,确保日志文件的管理和存储效率。