Flume 日志收集工具使用(文件到kafka)

Flume 日志收集工具使用(文件到kafka)

Flume是Cloudera提供的一个高可用的,高可靠的,分布式的海量日志采集、聚合和传输的系统,Flume支持在日志系统中定制各类数据发送方,用于收集数据;同时,Flume提供对数据进行简单处理,并写到各种数据接受方(可定制)的能力

本次使用用于将本地文件发送到kafka消息队列中,供分析段使用

flume使用依赖java环境

下载地址:https://flume.apache.org/download.html 下载apache-flume-1.9.0-bin.tar.gz

文档地址:https://flume.apache.org/releases/content/1.9.0/FlumeUserGuide.html

创建一个{name}.conf 文件,内容如下

# example.conf: A single-node Flume configuration

# Name the components on this agent
a1.sources = r1
a1.channels = c1
a1.sinks = k1

a1.sources.r1.type = TAILDIR
a1.sources.r1.channels = c1
a1.sources.r1.positionFile = /home/.../flume/taildir_position.json
a1.sources.r1.filegroups = f1 
a1.sources.r1.filegroups.f1 = /home/..../flume/.*.log
a1.sources.r1.headers.f1.headerKey1 = value1
a1.sources.r1.fileHeader = true
a1.sources.ri.maxBatchCount = 1000

# Describe the sink
a1.sinks.k1.channel = c1
a1.sinks.k1.type = org.apache.flume.sink.kafka.KafkaSink
a1.sinks.k1.kafka.topic = mytopic2
a1.sinks.k1.kafka.bootstrap.servers = ip:port
a1.sinks.k1.kafka.flumeBatchSize = 20
a1.sinks.k1.kafka.producer.acks = 1
a1.sinks.k1.kafka.producer.linger.ms = 1
a1.sinks.k1.kafka.producer.compression.type = snappy

# Use a channel which buffers events in memory
a1.channels.c1.type = memory
a1.channels.c1.capacity = 1000
a1.channels.c1.transactionCapacity = 100

# Bind the source and sink to the channel
a1.sources.r1.channels = c1
a1.sinks.k1.channel = c1

其中

a1.sources.r1.positionFile = /home/.../flume/taildir_position.json
用来记录监听日志的信息,比如上次读到哪了
a1.sources.r1.filegroups.f1 = /home/..../flume/.*.log
用来设置监听日志的目录
a1.sinks.k1.kafka.topic = mytopic2
用来设置要发送到kafka的topic
a1.sinks.k1.kafka.bootstrap.servers = ip:port
kafka地址
a1.sinks.k1.kafka.producer.compression.type = snappy
kafka压缩方式

启动命令:

到flume目录下执行

bin/flume-ng agent --conf conf --conf-file kafka.conf  --name a1 -Dflume.root.logger=INFO,console
bin/flume-ng 是执行文件
-conf-file kafka.conf 是刚刚写的conf

猜你喜欢

转载自blog.csdn.net/luslin1711/article/details/103602031