zl程序教程

您现在的位置是:首页 >  大数据

当前栏目

elk-日志方案--使用Filebeat收集日志并输出到Kafka

Kafka日志输出 -- 方案 收集 ELK Filebeat
2023-09-14 09:12:10 时间

 

1,Filebeat简介

Filebeat是一个使用Go语言实现的轻量型日志采集器。在微服务体系中他与微服务部署在一起收集微服务产生的日志并推送到ELK。
在我们的架构设计中Kafka负责微服务和ELK的分离,Filebeat负责收集微服务的日志并推送到Kafka中,如图:
 

2,Filebeat安装使用步骤

2.1 下载并解压Filebeat

在以上网址中下载和操作系统匹配的版本
其中CentOS属红帽系列选择RPM,Ubuntu属Debian系列选择DEB,其他Linux选择Linux通用。我用的win10选择Windows 64-bit,下载并解压到自定义目录(比如:C:\Programs\filebeat-6.5.1-windows-x86_64)
 

2 .2 编辑filebeat.yml配置文件

修改其中的input选项
 
#=========================== Filebeat inputs =============================
filebeat.inputs:
# Each - is an input. Most options can be set at the input level, so
# you can use different inputs for various configurations.
# Below are the input specific configurations.
- type: log
# Change to true to enable this input configuration.
enabled: true #此处默认为false,切记改为true.否则坑到天黑
# Paths that should be crawled and fetched. Glob based paths.
paths:
#- /var/log/*.log #Linux使用此处配置
- C:\Logs\*.log #Windows使用此配置
 
修改output选项,添加输出到kafka的配置
 
#================================ Outputs =====================================
 
# Configure what output to use when sending the data collected by the beat.
 
#-------------------------- Kafka output ------------------------------
output.kafka:
# Array of hosts to connect to.
hosts: ["192.168.8.32:9092"] #hosts是string数组类型,支持多个kafka实力地址(此处不是配置zookeeper地址)
topic: elklog        #kafka的topic名称
 
 

2.3 运行命令启动Filebeat

 Linux运行以下命令:
 sudo ./filebeat -e -c filebeat.yml
 Windows运行以下命令:
filebeat.exe -e -c filebeat.yml
 

3,测试

在我们配置好的input选项中的目录下,新建一个test.log文件,并写入测试字符串保存并关闭。
 
 可以看到Kafka已经有数据了
 
 如果ELK运行正常,Elasticsearch和Kibana中也有数据了。