案例七:启动一个flume采集数据程序,要求采集指定端口、指定目录、指定文件的数据,其中端口数据发送到HDFS和flume日志中,目录数据只发送给hdfs、文件数据只发送给logger
说明
source: 3
channel: 2
sink: 2
画图理解
配置文件编写
[root@node1 data]# cat portAndDirAndFileToHDFSAndFlumeAndLogger.conf
# 给flume采集进程agent起了一个别名 a1
# 定义flume进程中有几个source 以及每一个source的别名
a1.sources = r1 r2 r3
a1.channels = c1 c2
a1.sinks = k1 k2
# 定义flume进程中source连接到数据源信息
a1.sources.r1.type = netcat
a1.sources.r1.bind = localhost
a1.sources.r1.port = 44444
a1.sources.r2.type = spooldir
a1.sources.r2.spoolDir = /opt/test
a1.sources.r2.fileHeader = true
a1.sources.r3.type = exec
a1.sources.r3.command = tail -F /opt/a.txt
# sink info
a1.sinks.k2.type = logger
a1.sinks.k1.type = hdfs
#指定采集的数据存储到HDFS的哪个目录下
a1.sinks.k1.hdfs.path = hdfs://node1:9000/flume/%Y%m%d/%H
#上传文件的前缀
a1.sinks.k1.hdfs.filePrefix = port-
#上传文件的后缀
a1.sinks.k1.hdfs.fileSuffix = .log
##是否按照时间滚动文件夹
a1.sinks.k1.hdfs.round = true
##多少时间单位创建一个新的文件夹
a1.sinks.k1.hdfs.roundValue = 1
##重新定义时间单位
a1.sinks.k1.hdfs.roundUnit = hour
##是否使用本地时间戳
a1.sinks.k1.hdfs.useLocalTimeStamp = true
##积攒多少个Event才flush到HDFS一次
a1.sinks.k1.hdfs.batchSize = 1000
##设置文件类型,可支持压缩
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
# Use a channel which buffers events in memory
a1.channels.c1.type = memory
a1.channels.c1.capacity = 1000
a1.channels.c1.transactionCapacity = 100
a1.channels.c2.type = memory
a1.channels.c2.capacity = 1000
a1.channels.c2.transactionCapacity = 100
# Bind the source and sink to the channel
a1.sources.r1.channels = c1 c2
a1.sources.r2.channels = c1
a1.sources.r3.channels = c2
a1.sinks.k1.channel = c1
a1.sinks.k2.channel = c2
本文来自博客园,作者:jsqup,转载请注明原文链接:https://www.cnblogs.com/jsqup/p/16556662.html