Flume_Flume常用配置5_header + filter taildir.source_memory.channel_hdfs.sink

以下配置基于版本 apache-flume-1.8.0-bin


我们假定已经对Flume有一定了解,并且对Flume 的各个组件有一定了解。

我们演示一个基本的 
source  为 taildir源
channel 为 memory
sink 为 hdfs 类型
的配置示例:


上一个配置中,我们对spooldir 源进行了简单的讲解,也提出了spooldir 中存在的问题,这一章我们对 1.8新推出的

taildir 进行下讲解,taildir 可以完美解决 spooldir 中存在的问题。


我们对 taildir 的原理进行下简单的介绍,

taildir 对一个目录进行监测,目录不支持 正则,等表达式,

会生成一个json文件,其中记录了每个文件的消费偏移量。

1. 宕机后,会从偏移量继续消费 ,所以一般不存在数据重复发送的问题。


但是该功能为 1.8 的实验性功能,目前只支持linux 环境,下面是示例配置

我们在解压好的目录下创建 2个子目录  my-conf, my-bin

my-conf 存放了 对 agent (source, sink, channel) 的配置

my-bin 存放了  agent 的启动脚本


在上一篇的基础上,我们增加了 过滤器 文件压缩 的配置


这里我们要说一说文件压缩,

如果我们配置了文件压缩,在sink 中 就不需要配置后缀了,因为文件压缩默认会有一个后缀,所以我们不需要额外的后缀



my-conf



my-bin



配置文件

my-conf/flume-taildir-memory-hdfs_withhead-codec.properties

# example.conf: A single-node Flume configuration

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

# Describe/configure the source
hdfs_agent.sources.r1.type = TAILDIR
hdfs_agent.sources.r1.filegroups = f1
hdfs_agent.sources.r1.filegroups.f1 = /tmp/logs/tailDir/.*\.log
hdfs_agent.sources.r1.positionFile = /tmp/logs/tailDir/.flume/taildir_position.json

hdfs_agent.sources.r1.interceptors = i1 i2 i3

#拦截器配置
hdfs_agent.sources.r1.interceptors.i1.type = timestamp
hdfs_agent.sources.r1.interceptors.i1.preserveExisting = true

hdfs_agent.sources.r1.interceptors.i2.type = host
hdfs_agent.sources.r1.interceptors.i2.preserveExisting = true

hdfs_agent.sources.r1.interceptors.i3.type = static
hdfs_agent.sources.r1.interceptors.i3.key = country
hdfs_agent.sources.r1.interceptors.i3.value = China

# Describe the sink
hdfs_agent.sinks.k1.type = hdfs
hdfs_agent.sinks.k1.hdfs.path = hdfs://192.168.75.128:9000/test/flume/hdfs_filegroups_source_header_codec/%{host}/%Y-%m-%d/
#文件转存属性
hdfs_agent.sinks.k1.hdfs.rollInterval = 3600
hdfs_agent.sinks.k1.hdfs.rollSize = 1048576
hdfs_agent.sinks.k1.hdfs.rollCount = 20
#文件的名字
hdfs_agent.sinks.k1.hdfs.filePrefix = %{host}_%{country}_log_%Y%m%d_%H
#当设置压缩属性的时候,不应该指定 文件后缀,否则会覆盖默认的压缩格式的后缀
#hdfs_agent.sinks.k1.hdfs.fileSuffix = .txt
#使得上面按天分目录的设置起作用
hdfs_agent.sinks.k1.hdfs.useLocalTimeStamp = true
#序列化方式
hdfs_agent.sinks.k1.hdfs.serializer = text_with_headers
#输出方式
hdfs_agent.sinks.k1.hdfs.codeC = bzip2
#输出方式
hdfs_agent.sinks.k1.hdfs.fileType = CompressedStream
#下面属性 只针对于 avro_event
#hdfs_agent.sinks.k1.hdfs.serializer.compressionCodec = bzip2

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

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

执行脚本

my-bin/start_taildir_memory_hdfs_withhead_codec.sh

#!/bin/bash

ROOT_PATH=$(dirname $(dirname $(readlink -f $0)))
cd $ROOT_PATH

bin/flume-ng agent --conf ./conf/ -f my-conf/flume-taildir-memory-hdfs_withhead-codec.properties -Dflume.root.logger=INFO,console -n hdfs_agent




猜你喜欢

转载自blog.csdn.net/u010003835/article/details/80357166