下面给你一个 CentOS 上 Filebeat 连接 Kafka 的常规做法(以 RPM 安装为例,适用于 ELK 常见架构)。
sudo yum install -y filebeat
# 或
sudo rpm -ivh filebeat-8.x.x-x86_64.rpm
192.168.1.10:9092)filebeat-logs)编辑配置文件:
vi /etc/filebeat/filebeat.yml
output.kafka)filebeat.inputs:
- type: log
enabled: true
paths:
- /var/log/*.log
- /opt/app/logs/*.log
# 关闭 Elasticsearch 输出(默认是开启的)
output.elasticsearch:
enabled: false
# Kafka 输出
output.kafka:
enabled: true
hosts: ["192.168.1.10:9092"]
topic: "filebeat-logs"
partition.round_robin:
reachable_only: true
required_acks: 1
compression: gzip
max_message_bytes: 1000000
systemctl enable filebeat
systemctl start filebeat
查看状态:
systemctl status filebeat
tail -f /var/log/filebeat/filebeat
在 Kafka 服务器上:
kafka-console-consumer.sh \
--bootstrap-server 192.168.1.10:9092 \
--topic filebeat-logs \
--from-beginning
如果能看到 JSON 日志,说明连接成功。
9092 是否开放listeners / advertised.listenersKafka 若未开启自动创建:
kafka-topics.sh --create \
--topic filebeat-logs \
--bootstrap-server 192.168.1.10:9092 \
--partitions 3 \
--replication-factor 1
output.kafka:
hosts: ["kafka:9092"]
topic: "filebeat-logs"
username: "filebeat"
password: "password"
sasl.mechanism: PLAIN
ssl.enabled: true
如果你愿意,可以告诉我:
我可以直接帮你写一份可用配置。