Flume_Flume常用配置4_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 的启动脚本



my-conf



my-bin



配置文件

my-conf/flume-taildir-memory-hdfs.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

# 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/%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 = log_%Y%m%d_%H
hdfs_agent.sinks.k1.hdfs.fileSuffix = .txt
hdfs_agent.sinks.k1.hdfs.fileType = DataStream
hdfs_agent.sinks.k1.hdfs.useLocalTimeStamp = true

# 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.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.properties -Dflume.root.logger=INFO,console -n hdfs_agent




猜你喜欢

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