Flume_Flume常用配置3_spooldir.source_memory.channel_hdfs.sink

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


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

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


这里我们要对spooldir 源进行简单讲解:

spooldir 可以避免 exec 中 利用 tail -f  xxx.log  可能导致的数据重传或者, 输入流与拉取流速度不一致导致的数据丢失的问题。

具体的原理如下:

      spooldir 源可以监听 某个目录下文件的变化,并会将已经传输完成的文件 以 添加后缀的形式 进行重命名,

所以一般的用法是将完整的日志 拷贝进监视的目录中,然后让 spooldir 源对 数据进行拉取。


但还是存在着一定的问题,

1) 日志拉取一半,flume 进程被杀死,这时原始日志被拉取了一半,但是并未完全拉去完全,并不会重命名

2) 如果存在着与完成文件未改名前同名的文件,会flume 程序直接宕掉






我们在解压好的目录下创建 2个子目录  my-conf, my-bin
my-conf 存放了 对 agent (source, sink, channel) 的配置

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



my-conf



my-bin



配置文件

my-conf/flume-spooldir-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 = spooldir
hdfs_agent.sources.r1.spoolDir = /tmp/logs/spoolDir

# Describe the sink
hdfs_agent.sinks.k1.type = hdfs
hdfs_agent.sinks.k1.hdfs.path = hdfs://192.168.75.128:9000/test/flume/hdfs_spooldir_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_spooldir_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-spooldir-memory-hdfs.properties -Dflume.root.logger=INFO,console -n hdfs_agent

猜你喜欢

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