flume-taildir监控多目录下多个追加文件,并且实现断点续传

ゞ 浴缸里的玫瑰 2023-06-30 09:22 96阅读 0赞

说明

Exec source 适用于监控一个实时追加的文件,但不能保证数据不丢失;Spooldir Source 能够保证数据不丢失,且能够实现断点续传,但延迟较高,不能实时监控;而 Taildir Source 既能够实现断点续传,又可以保证数据不丢失,还能够进行实时监控。

实现步骤: 1.创建配置文件 flume-taildir-hdfs.conf

  1. 添加如下内容
  2. a3.sources = r3
  3. a3.sinks = k3
  4. a3.channels = c3
  5. # Describe/configure the source
  6. a3.sources.r3.type = TAILDIR
  7. a3.sources.r3.positionFile = /opt/module/flume/tail_dir.json
  8. a3.sources.r3.filegroups = f1
  9. a3.sources.r3.filegroups.f1 = /opt/module/flume/files/file.*
  10. # Describe the sink
  11. a3.sinks.k3.type = hdfs
  12. a3.sinks.k3.hdfs.path =
  13. hdfs://hadoop102:9000/flume/upload/%Y%m%d/%H
  14. #上传文件的前缀
  15. a3.sinks.k3.hdfs.filePrefix = upload- #是否按照时间滚动文件夹
  16. a3.sinks.k3.hdfs.round = true
  17. #多少时间单位创建一个新的文件夹
  18. a3.sinks.k3.hdfs.roundValue = 1
  19. #重新定义时间单位
  20. a3.sinks.k3.hdfs.roundUnit = hour
  21. #是否使用本地时间戳
  22. a3.sinks.k3.hdfs.useLocalTimeStamp = true
  23. #积攒多少个 Event 才 flush 到 HDFS 一次
  24. a3.sinks.k3.hdfs.batchSize = 100
  25. #设置文件类型,可支持压缩
  26. a3.sinks.k3.hdfs.fileType = DataStream
  27. #多久生成一个新的文件
  28. a3.sinks.k3.hdfs.rollInterval = 60
  29. #设置每个文件的滚动大小大概是 128M
  30. a3.sinks.k3.hdfs.rollSize = 134217700 #文件的滚动与 Event 数量无关
  31. a3.sinks.k3.hdfs.rollCount = 0
  32. # Use a channel which buffers events in memory
  33. a3.channels.c3.type = memory
  34. a3.channels.c3.capacity = 1000
  35. a3.channels.c3.transactionCapacity = 100
  36. # Bind the source and sink to the channel
  37. a3.sources.r3.channels = c3
  38. a3.sinks.k3.channel = c3

2、启动监控文件夹命令

flume-ng agent —conf conf/ —name a3 —conf-file job/flume-taildir-hdfs.conf

3、Taildir 说明:

Taildir Source 维护了一个 json 格式的 position File,其会定期的往 position File 中更新每个文件读取到的最新的位置,因此能够实现断点续传。Position File 的格式如下:
{“inode”:2496272,”pos”:12,”file”:”/opt/module/flume/files/file1.txt”}
{“inode”:2496275,”pos”:12,”file”:”/opt/module/flume/files/file2.txt”}
注:Linux 中储存文件元数据的区域就叫做 inode,每个 inode 都有一个号码,操作系统用 inode 号码来识别不同的文件,Unix/Linux 系统内部不使用文件名,而使用 inode 号码来识别文件。

发表评论

表情:
评论列表 (有 0 条评论,96人围观)

还没有评论,来说两句吧...

相关阅读