Flume --Source

本文详细介绍了Flume中多种源的配置方法,包括Avro、Exec、Spool、SequenceGenerator、TCPSyslog、HTTP等源的具体配置步骤及注意事项。

 使用avro源:监听Avro端口并从外部Avro客户端流接收事件。当与另一个(前一跳)水槽代理上的内置Avro接收器配对时,它可以创建分层集合拓扑。

1.配置flume【avro_r.conf】
#comonents
a1.sources = r1
a1.sinks = s1
a1.channels = c1

#source
a1.sources.r1.type = avro
a1.sources.r1.bind = 0.0.0.0
a1.sources.r1.port = 4141

#sink
a1.sinks.s1.type=logger

#channel
a1.channels.c1.type=memory

#bind
a1.sources.r1.channels=c1
a1.sinks.s1.channel=c1



2.启动
[hadoop@master conf]$ flume-ng agent --conf . --conf-file avro_r.conf --name a1 -Dflume.root.logger=INFO,console
3.通过flume-ng avro-client 命令发送avro数据消息
  $> flume-ng avro-client -H localhost -p 4141 -F helloworld(/home/hadoop/helloworld    helloworld是文件)




使用exec源:Exec source在启动时运行给定的Unix命令,并期望该进程在标准输出上持续生成数据(除非属性logStdErr设置为true)。如果进程出于某种原因退出,源程序也退出,并且不会产生进一步的数据。这意味着诸如cat [named pipe]或tail - f [file]之类的配置将在可能不产生日期的情况下生成所需的结果——前两个命令生成数据流,而后者生成单个事件和出口。======================


1.配置flume【exec-r.conf】
#comonents
a1.sources = r1
a1.sinks = s1
a1.channels = c1

#source
a1.sources.r1.type = exec
a1.sources.r1.command =cat /home/hadoop/helloworld

#sink
a1.sinks.s1.type=logger


#channel
a1.channels.c1.type=memory


#bind
a1.sources.r1.channels=c1
a1.sinks.s1.channel=c1


2.启动
[hadoop@master conf]$ flume-ng agent --conf . --conf-file exec-r.conf --name a1 -Dflume.root.logger=INFO,console
直接打印出文件的内容



使用spool源:

通过将文件放入磁盘上的“假脱机”目录中,该源代码允许您摄取数据。该源将监视指定的目录以查找新文件,并在新文件出现时解析事件。事件解析逻辑是可插拔的。在一个给定的文件被完全读取到通道后,它被重命名为表示完成(或可选删除)。
与Exec源不同,该源是可靠的,不会丢失数据,即使Flume重新启动或被杀死。为了交换这种可靠性,只能将不可变的、惟一命名的文件放入到假脱机目录中。水槽试图检测这些问题的条件,并将大声失败,如果它们被违反:
如果文件被写入到spooling目录中,Flume会将错误打印到日志文件并停止处理。
如果以后重用文件名,Flume将在日志文件中打印错误并停止处理。
为了避免上述问题,在将文件名移动到假脱机目录时,添加一个惟一标识符(例如时间戳)来记录文件名可能会很有用。
尽管该源具有可靠性保证,但如果发生某些下游故障,仍然存在重复事件的情况。这与其他Flume组件提供的保证一致。


【spool-r.conf】
#comonents
a1.sources = r1
a1.sinks = s1
a1.channels = c1

#source
a1.sources.r1.type = spooldir
a1.sources.r1.spoolDir=/home/hadoop/a


#sink
a1.sinks.s1.type=logger

#channel
a1.channels.c1.type=memory

#bind
a1.sources.r1.channels=c1
a1.sinks.s1.channel=c1

[hadoop@master conf]$ flume-ng agent --conf -file spool-r.conf --n a1 -Dflume.root.logger=INFO,console

[hadoop@master ~]$ mkdir a
[hadoop@master ~]$ echo helloworld >a/1.tst
[hadoop@master ~]$ echo helloworld >a/2.txt
[hadoop@master ~]$ echo jiayou >/3.txt


Sequence Generator Source
422/5000  
一个简单的序列生成器,使用计数器连续地生成事件,计数器从0开始,递增1,在totalEvents停止。当不能向通道发送事件时重试。有用的主要用于测试。在重试过程中,它保持重试消息的主体与之前相同,以便唯一事件的数量(在目的地重复删除之后)预期等于指定的totalEvents。


【seq-r.conf】
#comonents
a1.sources = r1
a1.sinks = s1
a1.channels = c1

#source
a1.sources.r1.type = seq


#sink
a1.sinks.s1.type=logger

#channel
a1.channels.c1.type=memory

#bind
a1.sources.r1.channels=c1
a1.sinks.s1.channel=c1
启动:
[hadoop@master conf]$ flume-ng agent --conf-file seq-r.conf --n a1 -Dflume.root.logger=INFO,console


TCPSyslog  Source

读取syslog数据并生成Flume事件。UDP将整个消息视为单个事件。TCP源为由换行符(' n ')分隔的每个字符串创建一个新事件。
syslogtcp-r.conf

#comonents
a1.sources = r1
a1.sinks = s1
a1.channels = c1

#source
a1.sources.r1.type = syslogtcp
a1.sources.r1.host = localhost
a1.sources.r1.port = 8888

#sink
a1.sinks.s1.type=logger

#channel
a1.channels.c1.type=memory

#bind
a1.sources.r1.channels=c1
a1.sinks.s1.channel=c1
启动:
[hadoop@master conf]$ flume-ng agent --conf-file syslogtcp-r.conf --n a1 -Dflume.root.logger=INFO,console


[hadoop@master network-scripts]$ nc localhost 8888
hello


HTTP Source

通过HTTP POST和GET接收Flume事件的源。GET只能用于实验。HTTP请求通过可插入的“处理程序”转换为flume事件,该“处理程序”必须实现HTTPSourceHandler接口。这个处理程序接受一个HttpServletRequest并返回一个flume事件列表。从一个Http请求处理的所有事件都提交到一个事务中的通道中,从而提高了文件通道等通道的效率。如果处理程序抛出异常,该源将返回400的HTTP状态。如果通道已满,或者源无法向通道添加事件,源将返回HTTP 503——暂时不可用状态。
【http-r.conf】
#comonents
a1.sources = r1
a1.sinks = s1
a1.channels = c1

#source
a1.sources.r1.type = http
a1.sources.r1.port = 8888

#sink
a1.sinks.s1.type=logger

#channel
a1.channels.c1.type=memory

#bind
a1.sources.r1.channels=c1
a1.sinks.s1.channel=c1
[hadoop@master conf]$ flume-ng agent --conf-file http-r.conf --n a1 -Dflume.root.logger=INFO,console




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值