在 CentOS 上使用 Filebeat 收集日志,一般流程如下(以 Elastic Stack / ELK 为例,也可以是直接输出到文件、Logstash、Kafka 等)。
curl、sudosudo rpm --import https://artifacts.elastic.co/GPG-KEY-elasticsearch
sudo cat > /etc/yum.repos.d/filebeat.repo <<EOF
[filebeat]
name=Elasticsearch repository for Filebeat
baseurl=https://artifacts.elastic.co/packages/8.x/yum
gpgcheck=1
gpgkey=https://artifacts.elastic.co/GPG-KEY-elasticsearch
enabled=1
autorefresh=1
type=rpm-md
EOF
sudo yum install filebeat -y
如果是 Elasticsearch 7.x,把
8.x改成7.x
配置文件路径:
/etc/filebeat/filebeat.yml
filebeat.inputs:
- type: log
enabled: true
paths:
- /var/log/nginx/access.log
- /var/log/nginx/error.log
output.elasticsearch:
hosts: ["http://localhost:9200"]
filebeat.inputs:
- type: log
enabled: true
paths:
- /opt/app/logs/*.log
fields:
app: my-app
fields_under_root: true
output.elasticsearch:
hosts: ["http://es-host:9200"]
output.logstash:
hosts: ["logstash-host:5044"]
output.kafka:
hosts: ["kafka1:9092"]
topic: logs-topic
sudo systemctl enable filebeat
sudo systemctl start filebeat
查看状态:
systemctl status filebeat
查看日志:
journalctl -u filebeat -f
curl http://localhost:9200/_cat/indices?v
在 Logstash 中配置 beats 输入并查看输出。
确保 Filebeat 能读取日志:
sudo usermod -aG adm filebeat
enabled: truepaths 是否正确rm -rf /var/lib/filebeat/registry
systemctl restart filebeat
/var/lib/docker/containers/*)/var/log/messages如果你有具体日志路径 / 输出目标(ES / Logstash / Kafka),我可以帮你写一份完整可用的 filebeat.yml。