• 大数据学习——采集目录到HDFS


    采集需求:某服务器的某特定目录下,会不断产生新的文件,每当有新文件出现,就需要把文件采集到HDFS中去

    根据需求,首先定义以下3大要素

    l  采集源,即source——监控文件目录 :  spooldir

    l  下沉目标,即sink——HDFS文件系统  :  hdfs sink

    l  source和sink之间的传递通道——channel,可用file channel 也可以用内存memory channel

    配置文件编写:

    vi spooldir-hdfs-sink.conf

    
    

    #定义三大组件的名称

    agent1.sources = source1

    agent1.sinks = sink1

    agent1.channels = channel1

    # 配置source组件

    agent1.sources.source1.type = spooldir

    agent1.sources.source1.spoolDir = /root/data/

    agent1.sources.source1.fileHeader = false

    #配置拦截器

    agent1.sources.source1.interceptors = i1

    agent1.sources.source1.interceptors.i1.type = timestamp

    # 配置sink组件

    agent1.sinks.sink1.type = hdfs

    agent1.sinks.sink1.hdfs.path =/weblog/flume-collection/%y-%m-%d/%H-%M

    agent1.sinks.sink1.hdfs.filePrefix = access_log

    agent1.sinks.sink1.hdfs.maxOpenFiles = 5000

    agent1.sinks.sink1.hdfs.batchSize= 100

    agent1.sinks.sink1.hdfs.fileType = DataStream

    agent1.sinks.sink1.hdfs.writeFormat =Text

    #滚动生成的文件按大小生成

    agent1.sinks.sink1.hdfs.rollSize = 102400

    #滚动生成的文件按行数生成

    agent1.sinks.sink1.hdfs.rollCount = 1000000

    #滚动生成的文件按时间生成

    agent1.sinks.sink1.hdfs.rollInterval = 60

    #开启滚动生成目录

    agent1.sinks.sink1.hdfs.round = true

    #以10为一梯度滚动生成

    agent1.sinks.sink1.hdfs.roundValue = 10

    #单位为分钟

    agent1.sinks.sink1.hdfs.roundUnit = minute

    # Use a channel which buffers events in memory

    agent1.channels.channel1.type = memory

    agent1.channels.channel1.capacity = 500000

    agent1.channels.channel1.transactionCapacity = 600

    agent1.channels.channel1.keep-alive = 120

    # Bind the source and sink to the channel

    agent1.sources.source1.channels = channel1

    agent1.sinks.sink1.channel = channel1

    添加数据

    aaa.txt

    13601249301     100     200     300     400     500     600     700
    13601249302     100     200     300     400     500     600     700
    13601249303     100     200     300     400     500     600     700
    13601249304     100     200     300     400     500     600     700
    13601249305     100     200     300     400     500     600     700

    执行命令

     bin/flume-ng agent -c conf -f conf/spooldir-hdfs-sink.conf -n agent1  -Dflume.root.logger=INFO,console   

    flume的source采用spoodir时! 目录下面不允许存放同名的文件,否则报错!

    Channel参数解释:

    capacity:默认该通道中最大的可以存储的event数量

    trasactionCapacity:每次最大可以从source中拿到或者送到sink中的event数量

    keep-alive:event添加到通道中或者移出的允许时间

    其他组件:Interceptor(拦截器)

    用于Source的一组Interceptor,按照预设的顺序在必要地方装饰和过滤events。

    内建的Interceptors允许增加event的headers比如:时间戳、主机名、静态标记等等

    定制的interceptors可以通过内省event payload(读取原始日志),实现自己的业务逻辑(很强大)

  • 相关阅读:
    bootstrap组件+模板地址
    10个自动化测试框架,测试工程师用起来
    IP地址分类(A类 B类 C类 D类 E类)
    来不及解释!Linux常用命令大全,先收藏再说
    凭借祖传配方年入21亿(王守义十三香),一生坚持不上市,亏待自己也要善待员工
    不同手指戴戒指的含义
    Soul App 是一款怎样的产品? SOUL APP 机缘巧合我开始使用 今天第四天内心想知道大家对它的感受 又其实并没有那么想大家把感受具象化再描述出来 嗯 还是希望大家能说一说(网恋需谨慎,小心骗子)
    解放双手,markdown文章神器,Typora+PicGo+七牛云图床实现自动上传图片
    度学习与自然语言处理
    软件测试面试之剖析面试官
  • 原文地址:https://www.cnblogs.com/feifeicui/p/10301122.html
Copyright © 2020-2023  润新知