大数据之Flume:实时监控多个文件

Exec source适用于监控一个实时追加的文件,但不能保证数据不丢失;
Spooldir Source能够保证数据不丢失,且能够实现断点续传,但延迟较高,不能实时监控,采集的目录,适合离线采集的场景;
Taildir Source既能够实现断点续传,又可以保证数据不丢失,还能够进行实时监控,既可以做离线采集也可以做实时采集。
在这里插入图片描述

1)案例需求:使用Flume监听整个目录的实时追加文件,并上传至HDFS
2)需求分析:
3)实现步骤:
1.创建配置文件flume-taildir-hdfs.conf
创建一个文件
[hadoop@hadoop101 job]$ vim flume-taildir-hdfs.conf
添加如下内容

a3.sources = r3
a3.sinks = k3
a3.channels = c3

# Describe/configure the source
a3.sources.r3.type = TAILDIR
a3.sources.r3.positionFile = /opt/module/flume/tail_dir.json
a3.sources.r3.filegroups = f1 f2
a3.sources.r3.filegroups.f1 = /opt/module/flume/files/file.*
a3.sources.r3.filegroups.f2 = /opt/module/flume/files2/hadoop.*

# Describe the sink
a3.sinks.k3.type = hdfs
a3.sinks.k3.hdfs.path = hdfs://hadoop101: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 = 60
#设置每个文件的滚动大小大概是128M
a3.sinks.k3.hdfs.rollSize = 134217700
#文件的滚动与Event数量无关
a3.sinks.k3.hdfs.rollCount = 0

# Use a channel which buffers events in memory
a3.channels.c3.type = memory
a3.channels.c3.capacity = 10000
a3.channels.c3.transactionCapacity = 1000

# Bind the source and sink to the channel
a3.sources.r3.channels = c3
a3.sinks.k3.channel = c3

2.启动监控文件夹命令

[hadoop@hadoop101 flume]$ bin/flume-ng agent -conf conf/ -n a3 -f job/flume-taildir-hdfs.conf
  1. 向files文件夹中追加内容
    在/opt/module/flume目录下创建files文件夹
[hadoop@hadoop101 flume]$ mkdir files

向upload文件夹中添加文件

[hadoop@hadoop101 files]$ echo hello >> file1.txt
[hadoop@hadoop101 files]$ echo hadoop >> file2.txt

5.查看HDFS上的数据
在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/weixin_43597208/article/details/113877670