3.3 实时读取目录文件到 HDFS

3.3.1 案例需求

实时读取目录文件到HDFS案例

3.3.2 需求分析

3.3.3 操作步骤

步骤1: 创建配置文件flume-dir-hdfs.conf

touch 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/module/flume/upload
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://hadoop201:9000/flume/upload/%Y%m%d/%H
#上传文件的前缀
a3.sinks.k3.hdfs.filePrefix = upload-
#是否按照时间滚动文件夹
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 = 600
#设置每个文件的滚动大小大概是128M
a3.sinks.k3.hdfs.rollSize = 134217700
#文件的滚动与Event数量无关
a3.sinks.k3.hdfs.rollCount = 0
#最小冗余数
a3.sinks.k3.hdfs.minBlockReplicas = 1

# 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, 开始监控文件夹

bin/flume-ng agent --conf conf/ --conf-file job/flume-dir-hdfs.conf --name a3

说明: 在使用Spooling Directory Source时 1)不要在监控目录中创建并持续修改文件 2)上传完成的文件会以.COMPLETED结尾 3)被监控文件夹每500毫秒扫描一次文件变动

步骤3: 创建 upload 目录

创建 upload 目录, 并向该目录中添加文件.

mkdir upload
cd upload
touch a.txt
touch b.log
touch c.tmp

步骤4: hdfs 上查看

步骤5: 查看 upload 目录

发现除了.tmp结尾的文件, 其他文件已经被重命名.

Copyright © 尚硅谷大数据 2019 all right reserved,powered by Gitbook
该文件最后修订时间: 2019-01-21 14:20:06

results matching ""

    No results matching ""