ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

Flume实战案例 -- 从HDFS上读取某个文件到本地目录

2021-06-20 02:03:35  阅读:196  来源: 互联网

标签:Flume HDFS sinks -- a1 k1 sink c1 channel


需求分析
  • 我们从HDFS上的特定目录下的文件,读取到本地目录下的特定目录下

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

    • 数据源组件,即source ——监控HDFS目录文件 : exec 'tail -f'

    • 下沉组件,即sink—— file roll sink

    • 通道组件,即channel——可用file channel 也可以用内存channel

flume配置文件开发
  • 配置文件编写:

    cd /bigdata/install/flume-1.9.0/conf/
    vim hdfs2local.conf
    
  • 内容如下

    # Name the components on this agent
    a1.sources = r1
    a1.sinks = k1
    a1.channels = c1
    
    # Describe/configure the source
    # 注意:不能往监控目中重复丢同名文件
    a1.sources.r1.type = exec
    a1.sources.r1.command = hdfs dfs -tail -f /hdfs2flume/test/a.txt
    a1.sources.r1.channels = c1
    
    # sink 配置信息
    a1.sinks.k1.type = file_roll
    a1.sinks.k1.channel = c1
    a1.sinks.k1.sink.directory = /bigdata/install/mydata/flume/hdfs2local
    
    a1.sinks.k1.sink.rollInterval = 3600
    a1.sinks.k1.sink.pathManager.prefix = event-
    a1.sinks.k1.sink.serializer = TEXT
    a1.sinks.k1.sink.batchSize = 100
    
    # Use a channel which buffers events in memory
    a1.channels.c1.type = memory
    # channel中存储的event的最大数目
    a1.channels.c1.capacity = 1000
    # 每次传输数据,从source最多获得event的数目或向sink发送的event的最大的数目
    a1.channels.c1.transactionCapacity = 100
    
    # Bind the source and sink to the channel
    a1.sources.r1.channels = c1
    a1.sinks.k1.channel = c1
    
  • 准备HDFS文件信息

    vi a.txt
    
    #输入一下内容,保存并推送到HDFS上
    1  zhangsan  21
    2  lisi  22
    3  wangwu  23
    4  zhaoliu  24
    5  guangyunchang  25
    6  gaojianli  27
    
    hdfs dfs -put ./a.txt /hdfs2flume/test/a.txt
    
  • 准备本地目录文件夹

    mkdir -p /bigdata/install/mydata/flume/hdfs2local
    
  • 启动flume

    cd /bigdata/install/flume-1.9.0
    bin/flume-ng agent -c ./conf -f ./conf/hdfs2local.conf -n a1 -Dflume.root.logger=INFO,console
    
  • 追加hdfs上a.txt文件内容,验证本地目录文件夹,如下图

标签:Flume,HDFS,sinks,--,a1,k1,sink,c1,channel
来源: https://www.cnblogs.com/tenic/p/14905791.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有