在Ubuntu系统中配置Filebeat的日志轮转,可以通过以下步骤实现:
logrotate工具安装logrotate(如果尚未安装):
sudo apt-get update
sudo apt-get install logrotate
创建或编辑logrotate配置文件:
Filebeat的日志通常位于/var/log/filebeat/filebeat。你可以创建一个新的配置文件或编辑现有的配置文件来指定日志轮转的规则。
创建一个新的配置文件:
sudo nano /etc/logrotate.d/filebeat
或者编辑现有的配置文件(如果有的话)。
添加日志轮转配置:
在logrotate.d/filebeat文件中添加以下内容:
/var/log/filebeat/filebeat {
daily
rotate 7
compress
delaycompress
missingok
notifempty
create 640 root adm
}
解释:
daily:每天轮转一次日志。rotate 7:保留7个轮转的日志文件。compress:压缩旧的日志文件。delaycompress:延迟压缩,直到下一次轮转。missingok:如果日志文件丢失,不会报错。notifempty:如果日志文件为空,不进行轮转。create 640 root adm:创建新的日志文件时设置权限和所有者。测试配置:
你可以手动测试logrotate配置是否正确:
sudo logrotate -f /etc/logrotate.d/filebeat
Filebeat本身也支持日志轮转,可以通过配置logging.file和logging.level来实现。
编辑Filebeat配置文件:
打开Filebeat的配置文件,通常位于/etc/filebeat/filebeat.yml:
sudo nano /etc/filebeat/filebeat.yml
配置日志文件路径和级别:
确保logging.file指向正确的日志文件路径,并设置合适的日志级别:
logging:
file:
path: /var/log/filebeat/filebeat
level: info
重启Filebeat服务: 保存配置文件并重启Filebeat服务以应用更改:
sudo systemctl restart filebeat
logrotate配置文件的权限正确,通常应该是644。logrotate配置中的路径。/var/log/logrotate.log来确认。通过以上步骤,你应该能够在Ubuntu系统中成功配置Filebeat的日志轮转。