3.采集数据(将模拟好的数据采集到HDFS上)

fileToHdfs.conf文件

#sources别名:r1
a1.sources = r1  
#sink别名:k1
a1.sinks = k1
#channel别名:c1
a1.channels = c1

# 定义flume的source数据源 ---文件
a1.sources.r1.type = exec
#监听的文件  车流量数据文件
a1.sources.r1.command = tail -F /opt/data/car_flow.csv

# 定义flume的channel----使用基于kafka的channel
a1.channels.c1.type = memory
a1.channels.c1.capacity = 15000
a1.channels.c1.transactionCapacity = 10000
a1.channels.c1.byteCapacity = 800000

# 定义sink----console---hdfs
a1.sinks.k1.type = hdfs
a1.sinks.k1.hdfs.path = hdfs://HadoopCluster/project/%Y%m%d/
#上传文件的前缀
a1.sinks.k1.hdfs.filePrefix = flow
a1.sinks.k1.hdfs.fileSuffix = .csv
##是否按照时间滚动文件夹
a1.sinks.k1.hdfs.round = true
##多少时间单位创建一个新的文件夹
a1.sinks.k1.hdfs.roundValue = 24
##重新定义时间单位
a1.sinks.k1.hdfs.roundUnit = hour
##是否使用本地时间戳
a1.sinks.k1.hdfs.useLocalTimeStamp = true
##积攒多少个Event才flush到HDFS一次
a1.sinks.k1.hdfs.batchSize = 5000
##设置文件类型,可支持压缩
a1.sinks.k1.hdfs.fileType = DataStream
##多久生成一个新的文件
a1.sinks.k1.hdfs.rollInterval = 60
##设置每个文件的滚动大小
a1.sinks.k1.hdfs.rollSize = 134217700
##文件的滚动与Event数量无关
a1.sinks.k1.hdfs.rollCount = 0
##最小冗余数
a1.sinks.k1.hdfs.minBlockReplicas = 1


# 整合一个flume进程中channel source  sink 
a1.sources.r1.channels = c1
a1.sinks.k1.channel = c1

通过命令行模拟生产数据

flume-ng agent -n a1 -f fileToHdfs.conf -Dflume.root.logger=INFO,console

cat monitor_car_flow.csv >> car_flow.csv
posted @ 2022-09-15 10:26  jsqup  阅读(71)  评论(0编辑  收藏  举报