Flume 的应用3(多目录多文件(taildir source、memory channel、hdfs sink))

Flume 的应用3(taildir source、memory channel、hdfs sink)

2.4 实时监控多目录下的多个追加文件
  • Exec source 适用于监控一个实时追加的文件,不能实现断点续传;Spooldir Source 适合用于同步新文件,但不适合对实时追加日志的文件进行监听并同步;而 Taildir Source 适合用于监听多个实时追加的文件,并且能够实现断点续传

1)案例需求:

  • 使用 Flume 监听整个目录的实时追加文件,并上传至HDFS

2)需求分析:

在这里插入图片描述

3)实现步骤:

(1)创建配置文件 taildir-flume-hdfs.conf

  • 创建一个文件
[xiaoxq@hadoop105 jobs]$ vim taildir-flume-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-1.9.0/tail_dir.json
a3.sources.r3.filegroups = f1 f2
a3.sources.r3.filegroups.f1 = /opt/module/flume-1.9.0/testfiles/file1/file1.txt
a3.sources.r3.filegroups.f2 = /opt/module/flume-1.9.0/testfiles/file2/file2.txt

# Describe the sink
a3.sinks.k3.type = hdfs
a3.sinks.k3.hdfs.path =/flume/upload2/%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 = 1000
a3.channels.c3.transactionCapacity = 100

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

在这里插入图片描述

(2)启动监控文件夹命令

[xiaoxq@hadoop105 flume-1.9.0]$ bin/flume-ng agent -c conf/ -f jobs/taildir-flume-hdfs.conf -n a3

(3)向files文件夹中追加内容

  • 在/opt/module/flume-1.9.0目录下创建testfiles/文件夹
[xiaoxq@hadoop105 flume-1.9.0]$ mkdir -p testfiles/file1
[xiaoxq@hadoop105 flume-1.9.0]$ mkdir -p testfiles/file2
  • 向 upload 文件夹中添加文件
[xiaoxq@hadoop105 file1]$ pwd
/opt/module/flume-1.9.0/testfiles/file1
[xiaoxq@hadoop105 file1]$ echo hello >> file1.txt

[xiaoxq@hadoop105 file2]$ echo world >> file2.txt

(4)查看HDFS上的数据

在这里插入图片描述

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

Taildir 说明:

​ Taildir Source 维护了一个 json 格式的 position File,其会定期的往 position File 中更新每个文件读取到的最新的位置,因此能够实现断点续传。Position File 的格式如下:
在这里插入图片描述

Linux 中储存文件元数据的区域就叫做 inode,每个 inode 都有一个号码,操作系统用 inode 号码来识别不同的文件,Unix/Linux 系统内部不使用文件名,而使用 inode 号码来识别文件

  • 小结

  • taildir source
    1.首先如果需要追踪多目录 需要配置filegroups 然后分别给对应的filegroups 赋值(文件的绝对路径)
    2.taildir 如果想要完成断点续传:需要记录位置信息(inode pos path) 这三个改任何一个都能改变文件读取的位置
    
  • 2
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值