在CentOS上,Filebeat是一个轻量级的日志收集器,用于将日志文件或日志流发送到各种输出目标,如Elasticsearch、Logstash等。以下是Filebeat在CentOS上进行数据传输的基本步骤:
下载Filebeat
wget https://artifacts.elastic.co/downloads/beats/filebeat/filebeat-7.15.0-amd64.deb
安装Filebeat
sudo dpkg -i filebeat-7.15.0-amd64.deb
启动并启用Filebeat服务
sudo systemctl start filebeat
sudo systemctl enable filebeat
Filebeat的主要配置文件位于/etc/filebeat/filebeat.yml
。你需要根据你的需求修改这个文件。
filebeat.inputs:
- type: log
enabled: true
paths:
- /var/log/*.log
output.elasticsearch:
hosts: ["localhost:9200"]
index: "filebeat-%{[agent.version]}-%{+yyyy.MM.dd}"
如果你希望将日志发送到Logstash而不是Elasticsearch,可以这样配置:
output.logstash:
hosts: ["localhost:5044"]
确保配置文件无误后,重新启动Filebeat服务:
sudo systemctl restart filebeat
sudo systemctl status filebeat
Elasticsearch:
tail -f /var/log/elasticsearch/filebeat.log
Logstash:
tail -f /var/log/logstash/logstash-plain.log
你可以在Filebeat中添加处理器来修改日志数据。例如,添加一个处理器来解析JSON日志:
processors:
- decode_json_fields:
fields: ["message"]
target: ""
overwrite_keys: true
你可以在Filebeat中添加自定义字段:
fields:
custom_field: "custom_value"
Filebeat提供了丰富的监控和调试选项,可以通过以下方式启用:
启用调试日志:
sudo filebeat modules enable system
sudo filebeat setup
sudo systemctl restart filebeat
查看模块状态:
sudo filebeat modules list
通过以上步骤,你应该能够在CentOS上成功配置和运行Filebeat,并将日志数据传输到Elasticsearch或Logstash。