mkdir /usr/local/flume
cd /usr/local/flume
tar -zxvf apache-flume-1.8.0-bin.tar.gz
rm -rf apache-flume-1.8.0-bin.tar.gz
cd /usr/local/flume/apache-flume-1.8.0-bin/conf/
vim flume-dir-hdfs.conf
添加如下内容
a3.sources = r3
a3.sinks = k3
a3.channels = c3
# Describe/configure the source
a3.sources.r3.type = spooldir
a3.sources.r3.spoolDir = /opt/log
a3.sources.r3.fileSuffix = .COMPLETED
a3.sources.r3.fileHeader = true
#忽略所有以.tmp 结尾的文件,不上传
a3.sources.r3.ignorePattern = ([^ ]*\.tmp)
# Describe the sink
a3.sinks.k3.type = hdfs
a3.sinks.k3.hdfs.path = hdfs://hadoop111:9000/flume/log/%Y%m%d/%H
#上传文件的前缀
a3.sinks.k3.hdfs.filePrefix = log
#是否按照时间滚动文件夹
a3.sinks.k3.hdfs.round = true
#多少时间单位创建一个新的文件夹
a3.sinks.k3.hdfs.roundValue = 1
#重新定义时间单位
a3.sinks.k3.hdfs.roundUnit = hour
#是否使用本地时间戳
a3.sinks.k3.hdfs.useLocalTimeStamp = true
#积攒多少个 Event 才 flush 到 HDFS 一次
a3.sinks.k3.hdfs.batchSize = 100
#设置文件类型,可支持压缩
a3.sinks.k3.hdfs.fileType = DataStream
#多久生成一个新的文件
a3.sinks.k3.hdfs.rollInterval = 60
#设置每个文件的滚动大小大概是 128M
a3.sinks.k3.hdfs.rollSize = 134217700
#文件的滚动与 Event 数量无关
a3.sinks.k3.hdfs.rollCount = 0
# Use a channel which buffers events in memory
a3.channels.c3.type = memory
a3.channels.c3.capacity = 1000
a3.channels.c3.transactionCapacity = 100
# Bind the source and sink to the channel
a3.sources.r3.channels = c3
a3.sinks.k3.channel = c3
2.修改配置文件 flume-env.sh
cp flume-env.sh.template flume-env.sh
vim flume-env.sh
export JAVA_HOME=/usr/local/java/jdk1.8.0_211
3. 启动监控文件夹命令
./flume-ng agent -c ../conf/ -f ../conf/flume-dir-hdfs.conf -n a3 -Dflume.root.logger=INFO,console
说明:在使用 Spooling Directory Source 时
不要在监控目录中创建并持续修改文件
上传完成的文件会以.COMPLETED 结尾
被监控文件夹每 500 毫秒扫描一次文件变动
4. 向 lod 文件夹中添加文件
在/opt/log 目录下创建 b.txt 文件夹
mkdir b.txt
cp b.txt log/
查看
hadoop fs -cat /flume/log/20200214/01/log.1581660455517.tmp
作者:可爱的杨一凡