案例五:启动一个采集数据进程,将监听到的端口数据输出到HDFS分布式文件系统上()

说明

source: netcat
sink: hdfs

脚本编写

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

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

# sink info
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

# Bind the source and sink to the channel
a1.sources.r1.channels = c1
a1.sinks.k1.channel = c1

监听端口

telnet localhost 44444
————————

说明

source: netcat
sink: hdfs

脚本编写

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

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

# sink info
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

# Bind the source and sink to the channel
a1.sources.r1.channels = c1
a1.sinks.k1.channel = c1

监听端口

telnet localhost 44444