• Flume(4)实用环境搭建:source(spooldir)+channel(file)+sink(hdfs)方式


    一、概述:

    在实际的生产环境中,一般都会遇到将web服务器比如tomcat、Apache等中产生的日志倒入到HDFS中供分析使用的需求。这里的配置方式就是实现上述需求。

    二、配置文件:

    #agent1 name
    agent1.sources=source1
    agent1.sinks=sink1
    agent1.channels=channel1
    
    
    #Spooling Directory
    #set source1
    agent1.sources.source1.type=spooldir
    agent1.sources.source1.spoolDir=/opt/flumetest/data
    
    agent1.sources.source1.channels=channel1
    agent1.sources.source1.fileHeader = false
    agent1.sources.source1.interceptors = i1
    agent1.sources.source1.interceptors.i1.type = timestamp
    
    #set sink1
    agent1.sinks.sink1.type=hdfs
    agent1.sinks.sink1.hdfs.path=/home/hdfs/flume/logs
    agent1.sinks.sink1.hdfs.fileType=DataStream
    agent1.sinks.sink1.hdfs.writeFormat=TEXT
    agent1.sinks.sink1.hdfs.rollInterval=1
    agent1.sinks.sink1.channel=channel1
    agent1.sinks.sink1.hdfs.filePrefix=%Y-%m-%d
    
    #set channel1
    agent1.channels.channel1.type=file
    agent1.channels.channel1.checkpointDir=/opt/flumetest/cp/point
    agent1.channels.channel1.dataDirs=/opt/flumetest/cp

    三、执行下述命令:

    执行之前先确保上面配置文件中定义的文件夹都已经存在。

    bin/flume-ng agent -n agent1 -c conf -f study/logs2hdfs.conf -Dflume.root.logger=DEBUG,console

    source文件夹中的日志列表如下:

    image

    四、查看hdfs中的数据:

    image

    可以看到里面的数据文件都很小,这跟配置有关系,因为sink的配置里rollInterval配置的时间间隔太小导致的。可以根据需求在进行调整。

  • 相关阅读:
    超市帐单系统
    JavaOOP
    拦截器的工作原理是什么?
    struts2
    500错误
    idea添加struts框架后报错
    2019春第九周作业
    2019春第八周作业
    2019春第七周作业
    2019春第六周作业
  • 原文地址:https://www.cnblogs.com/tq03/p/5154898.html
Copyright © 2020-2023  润新知