我们已经了解了使用flume监听端口以及文件内容,本节将展示使用flume去监听一个文件夹并且上传其中的文件到HDFS。
a1.sources = r1
a1.sinks = k1
a1.channels = c1
# Describe/configure the source
a1.sources.r1.type = spooldir
a1.sources.r1.spoolDir = /root/upload
a1.sources.r1.basenameHeader = true
a1.sources.r1.basenameHeaderKey = fileName
# Describe the sink
a1.sinks.k1.type = hdfs
a1.sinks.k1.hdfs.path = hdfs://192.168.100.200:9000/flume/
a1.sinks.k1.hdfs.filePrefix = %{fileName}
# 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.channels.c1.type = file
cp /root/hadoop-2.5.2/share/hadoop/common/*.jar /root/apache-flume-1.8.0-bin/lib/
cp /root/hadoop-2.5.2/share/hadoop/common/lib/*.jar /root/apache-flume-1.8.0-bin/lib/
# 进入flume启动目录
cd /root/apache-flume-1.8.0-bin/bin
# 启动flume并申明a1服务
./flume-ng agent -c ../conf -f ../conf/flume-conf.properties -n a1 -Dflume.root.logger=INFO,console
# 创建对应的文件夹
mkdir -p /root/upload
不断在/root/upload中加入新的文件夹及其文件,查看HDFS存储。
以上就是通过flume监听文件夹变化并上传文件到HDFS。
原文:https://www.cnblogs.com/alichengxuyuan/p/12576879.html