Flume6 实时监控目录下的多个追加文件

Flume6 实时监控目录下的多个追加文件

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

案例需求

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

需求分析

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-ZVs7Nsly-1606096675366)(C:\Users\Auraros\AppData\Roaming\Typora\typora-user-images\image-20201121185941474.png)]

实验步骤

  • 建配置文件 flume-file-logger.conf

    创建一个文件

    [atguigu@hadoop102 job]$ touch flume-file-logger.conf
    

    打开文件

    [atguigu@hadoop102 job]$ vim flume-file-logger.conf
    

    添加如下内容

    # Name the components on this agent
    a1.sources = r1
    a1.sinks = k1
    a1.channels = c1
    
    # Describe/configure the source
    a1.sources.r1.type = TAILDIR
    a1.sources.r1.filegroups = f1,f2
    a1.sources.r1.filegroups.f1 = /opt/module/flume/files/file1.txt
    a1.sources.r1.filegroups.f2 = /opt/module/flume/files/file2.txt
    a1.sources.r1.positionFile = /opt/module/flume/position/position.json
    
    # Describe the sink
    a1.sinks.k1.type = logger
    
    # 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
    
  • 启动监控文件夹命令

    [atguigu@hadoop102 flume]$ bin/flume-ng agent -c conf/ -f job/flume-file-logger.conf -n a1 -Dflume.root.logger=INFO,console
    
  • 向 files 文件夹中添加文件

    在/opt/module/flume 目录下创建 upload 文件夹

    [atguigu@hadoop102 flume]$ mkdir files
    

    向 files 文件夹中的文件添加内容

    [atguigu@hadoop102 files]$ echo "hello" >> file1.txt
    [atguigu@hadoop102 files]$ echo "lili" >> file2.txt
    
  • 将flume下线,然后追加其他数据

    [atguigu@hadoop102 files]$ echo "hello2" >> file1.txt
    [atguigu@hadoop102 files]$ echo "lili2" >> file2.txt
    
  • 然后重新上线

    [atguigu@hadoop102 flume]$ bin/flume-ng agent -c conf/ -f job/flume-file-logger.conf -n a1 -Dflume.root.logger=INFO,consolent -c conf/ -f job/flume-file-logger.conf -n a1 -Dflume.root.logger=INFO,console```
    
    
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值