zoukankan      html  css  js  c++  java
  • Flume-Spooling Directory Source 监控目录下多个新文件

    使用 Flume 监听整个目录的文件,并上传至 HDFS。

    一、创建配置文件 flume-dir-hdfs.conf

    https://flume.apache.org/FlumeUserGuide.html#spooling-directory-source

    # Name the components on this agent
    a3.sources = r3
    a3.sinks = k3
    a3.channels = c3
    
    # Describe/configure the source
    a3.sources.r3.type = spooldir
    a3.sources.r3.spoolDir = /tmp/upload
    # 给 spoolDir 目录中文件添加的后缀,区分记录与未记录(先记录后改名)
    a3.sources.r3.fileSuffix = .COMPLETED
    a3.sources.r3.fileHeader = true
    # 忽略所有以.tmp 结尾的文件,不上传
    a3.sources.r3.ignorePattern = ([^ ]*.tmp)
    
    # Describe the sink
    a3.sinks.k3.type = hdfs
    a3.sinks.k3.hdfs.path = hdfs://h136: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 = 1000
    a3.channels.c3.transactionCapacity = 100
    
    # Bind the source and sink to the channel
    a3.sources.r3.channels = c3
    a3.sinks.k3.channel = c3

    二、启动

    cd /opt/apache-flume-1.9.0-bin/
    bin/flume-ng agent --conf conf/ --name a3 --conf-file /tmp/flume-job/flume-dir-hdfs.conf -Dflume.root.logger=INFO,console

    三、测试

    vim /tmp/123.txt
    
    123
    456
    789
    
    cp /tmp/123.txt /tmp/upload/
    cp /tmp/123.txt /tmp/upload/456.txt
    cp /tmp/123.txt /tmp/upload/789.txt

    已记录的文件会自动加上后缀。若复制以 tmp 结尾的文件 Flume 不记录,在配置中已忽略。

    说明:在使用 Spooling Directory Source 时不要在监控目录中创建并持续修改文件,上传完成的文件会以 .COMPLETED 结尾,被监控文件夹每 500 毫秒扫描一次文件变动。

    HDFS 上的文件

  • 相关阅读:
    lower版购物车模拟
    字典的增删改查和操作
    生成四位验证码
    列表的增删改查和操作
    根据输入字符串,分别计算大写,小写,数字,标点的个数
    检查一个数是不是质数
    非诚勿扰,选心动女生(小游戏)
    汉诺塔的实现
    一个纯虚函数导致的问题
    Hello World 之 CGAL
  • 原文地址:https://www.cnblogs.com/jhxxb/p/11557970.html
Copyright © 2011-2022 走看看