案例六:启动一个采集数据进程,采集端口和文件内容数据,其中端口数据输出到flume日志中,同时需要输出到HDFS上,文件内容只需要输出到HDFS上

说明

source: 2
channel: 2
sink: 2

配置文件

# 给flume采集进程agent起了一个别名  a1  
# 定义flume进程中有几个source 以及每一个source的别名
a1.sources = r1 r2
a1.sinks = k1 k2
a1.channels = c1 c2

# 定义flume进程中source连接到数据源信息
a1.sources.r1.type = netcat
a1.sources.r1.bind = localhost
a1.sources.r1.port = 44444

a1.sources.r2.type = exec
a1.sources.r2.command = tail -f /opt/test/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 = c2
a1.sinks.k1.channel = c2
a1.sinks.k2.channel = c1
posted @ 2022-08-06 09:28  jsqup  阅读(20)  评论(0编辑  收藏  举报