一、filebeat介绍
Filebeat是一个用于集中和转发日志数据的轻量级传送工具,是elk中的一员。在此项目中使用filebeat对web应用服务器产生的日志进行收集并推送给kafka服务器集群。在项目中充当生产者的角色。
二、filebeat安装
在web应用服务器上
rpm --import https://packages.elastic.co/GPG-KEY-elasticsearch
vim /etc/yum.repos.d/fb.repo
[elastic-7.x] name=Elastic repository for 7.x packages baseurl=https://artifacts.elastic.co/packages/7.x/yum gpgcheck=1 gpgkey=https://artifacts.elastic.co/GPG-KEY-elasticsearch enabled=1 autorefresh=1 type=rpm-md
yum install filebeat -y
三、filebeat配置
vim etc/filebeat/filebeat.yml
filebeat.inputs:
- type: log
# Change to true to enable this input configuration.
enabled: true
# Paths that should be crawled and fetched. Glob based paths.
paths:
- /var/log/nginx/access.log
#==========------------------------------kafka--------------------------------
output.kafka:
hosts: ["192.168.22.2:9092","192.168.22.3:9092","192.168.22.4"]
topic: nginxlog
keep_alive: 10s
四、测试
- 在kafka集群上创建话题
bin/kafka-topics.sh --create --zookeeper 192.168.22.2:2181 --replication-factor 3 --partitions 1 --topic nginxlog
- 启动filebeat
systemctl start filebeat
验证filebeat是否成功运行ps -ef |grep filebeat
- 在kafka中创建一个消费者
bin/kafka-console-consumer.sh --bootstrap-server 192.168.22.3:9092 --topic nginxlog --from-beginning
如果能消费到数据,说明filebeat能成功产生数据。