以下是CentOS中Filebeat的监控策略及配置要点:
安装Filebeat
通过官方仓库或手动下载安装包安装,如:
sudo yum install filebeat -y  # CentOS 7/8  
sudo rpm -ivh filebeat-*.rpm  # 手动安装  
配置监控目标
编辑/etc/filebeat/filebeat.yml,指定日志路径、文件类型及过滤规则:
filebeat.inputs:  
- type: log  
  enabled: true  
  paths:  
    - /var/log/*.log  
    - /var/log/messages  
  ignore_older: 72h  # 忽略超过72小时的日志  
- type: log  
  paths:  
    - /var/log/nginx/access.log  
    - /var/log/nginx/error.log  
  exclude_files: ['\.gz$']  # 排除压缩文件  
设置输出目标
将日志发送至Elasticsearch或Logstash:
output.elasticsearch:  
  hosts: ["localhost:9200"]  
  index: "filebeat-%{yyyy.MM.dd}"  # 按日期动态生成索引  
output.logstash:  
  hosts: ["localhost:5044"]  
启用高级功能
filebeat.modules:  
- module: nginx  
  access:  
    enabled: true  
    var.paths: ["/var/log/nginx/access.log"]  
processors提取字段或过滤内容,如使用dissect解析日志格式。优化性能与可靠性
filebeat.yml中设置logging.level(如info/debug),控制日志详细程度。logging.files参数设置日志文件大小、保留天数等。filebeat.autodiscover自动识别日志源。启动与验证
sudo systemctl start filebeat  
sudo systemctl enable filebeat  
# 验证配置是否正确  
sudo filebeat -e -c /etc/filebeat/filebeat.yml -d "publish"  
# 查看日志输出  
sudo tail -f /var/log/filebeat/filebeat.log  
可视化与告警
关键配置文件路径:
/etc/filebeat/filebeat.yml/var/log/filebeat/filebeat.log参考来源: