Flume组件配置

安装好CDH之后,flume就可以通过简单的配置,作为服务在后台运行了。但是要让flume真正为我所用,还是需要根据业务场景,写出有针对性地配置文件才行。

换句话说,flume作为服务在后台运行,它什么都能干,只要你说清楚需要它干什么。你把你需要flume干的事情,写成标准格式的配置文件,flume就能干活了。

所以,我们把flume应用分成3步:

  1. 理解你的应用场景
  2. 写出具体的配置文件
  3. 执行你的配置文件

为了说明以上问题,我们做一个案例。

  1. 理解你的应用场景 假设用户会不定期产生一些数据文件,然后希望能够及时在hdfs系统里看到这些文件。 对于这样的业务场景,我们按照输入、渠道、输出进行分析。其中,输入是数据文件;渠道没有特殊要求,直通即可;输出是hdfs。 分析结束,我们就可以知道采用哪些组件来配合工作了。输入我们可以采用Spooling Directory Source;渠道我们可以选择Memory或者File;输出我们可以选择HDFS Sink

  2. 写出具体的配置文件

#filename :  example.conf
# example.conf: A single-node Flume configuration

# Name the components on this agent
a1.sources = r1
a1.sinks = k1
a1.channels = c1

# Describe/configure the source
a1.sources.r1.type = spooldir
a1.sources.r1.spoolDir = /data/tmp
a1.sources.r1.fileHeader= true

# Describe the sink
a1.sinks.k1.type = hdfs
a1.sinks.k1.hdfs.path=/user/history/
a1.sinks.k1.hdfs.filePrefix=mac-
a1.sinks.k1.hdfs.fileSuffix=.txt
# 这个参数很重要。当事件的大小超过256M,才拆分,否则就作为1个文件 。
# 这种做法,避免将一个文件拆分成一条条。
a1.sinks.k1.hdfs.rollSize=267386880
a1.sinks.k1.hdfs.rollCount=0
# 文件的类型选择DataStream,则文件格式保持原样
a1.sinks.k1.hdfs.fileType=DataStream

# 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

  1. 执行你的配置文件.记得在flume agent服务所在节点上运行
export JAVA_HOME=/usr/java/jdk1.7.0_67-cloudera 
flume-ng agent --conf conf --conf-file example.conf --name a1 -Dflume.root.logger=INFO,console

  1. 检查HDFS上,文件是否生成。

转载于:https://my.oschina.net/pearma/blog/843476

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值