以下配置基于版本 apache-flume-1.8.0-bin
我们假定已经对Flume有一定了解,并且对Flume 的各个组件有一定了解。
我们演示一个基本的source 为 exec源
channel 为 memory
sink 为 hdfs类型
的配置示例:
请确保先安装了HDFS , 并对Hadoop 有一定了解,不懂得请自行百度,或者参看博主的Hadoop 相关搭建的文章。
我们在解压好的目录下创建 2个子目录 my-conf, my-bin
my-conf 存放了 对 agent (source, sink, channel) 的配置
my-bin 存放了 agent 的启动脚本
my-conf
my-bin
配置文件
my-conf/flume-exec-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 = exec
hdfs_agent.sources.r1.command = tail -F /tmp/log/source
# Describe the sink
hdfs_agent.sinks.k1.type = hdfs
hdfs_agent.sinks.k1.hdfs.path = hdfs://192.168.75.128:9000/test/flume/hdfs_exec_source/%Y-%m-%d/
hdfs_agent.sinks.k1.hdfs.rollInterval = 3600
hdfs_agent.sinks.k1.hdfs.rollSize = 1048576
hdfs_agent.sinks.k1.hdfs.rollCount = 50
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
这里要特别注意这个属性, 时区一定要指定,否则会抛出异常
hdfs_agent.sinks.k1.hdfs.useLocalTimeStamp = true
启动脚本
my-bin/start_exec_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-exec-memory-hdfs.properties -Dflume.root.logger=INFO,console -n hdfs_agent