flume学习05---Exec Source

Exec Source

Exec Source在启动时运行给定的Unix命令,并期望进程在标准输出上产生连续的数据(除非属性logStdErr设置为true,否则stderr将被丢弃)。 如果进程由于任何原因退出,source也会退出,并且不会生成更多数据。 这意味着诸如cat [named pipe]tail -F [file]之类的配置将产生期望的结果,其中日期可能不会 - 前两个命令产生数据流,其中后者产生单个事件并退出。

必需属性以粗体显示。
type必须是exec
command是unix命令
这里写图片描述

警告:

ExecSource和其他异步Source的问题是,source不能保证如果没有把event放到客户端知道的channel中。在这种情况下,数据将丢失。
例如,最常见的要求之一是tail -F [file]类的用例,其中应用程序写入磁盘上的日志文件,Flume tail这个文件,将每行作为event发送。虽然这是可能的,但有一个明显的问题;如果channel填满并且Flume不能发送事件会发生什么? Flume没有办法向应用程序写入日志文件,它需要保留日志或由于某种原因事件尚未发送。如果这没有作用,您只需要知道这一点:您的应用程序不能保证在使用单向异步接口(如ExecSource)时接收到数据!
作为此警告的延伸,并且完全清楚,在使用此源时对事件传递绝对保证为零。为了获得更高的可靠性保证,请考虑Spooling Directory Source或direct integration with Flume via the SDK.。
注意:
你可以使用ExecSource从Flume 0.9x(flume og)模拟TailSource。 只需使用unix命令tail -F / full / path / to / your / file。 参数-F在这种情况下比-f更好,因为它也将跟随文件旋转。

Example for agent named a1:

a1.sources = r1
a1.channels = c1
a1.sources.r1.type = exec
a1.sources.r1.command = tail -F /var/log/secure
a1.sources.r1.channels = c1

“shell”配置用于通过命令shell(例如Bash或Powershell)调用“command”。 “command”作为参数传递给shell以便执行。 这允许command使用shell中的特性,例如 wildcards, back ticks, pipes, loops, conditionals 等。在没有shell配置的情况下,command将被直接调用。 shell的通用值:'/ bin / sh -c','/ bin / ksh -c','cmd / c','powershell -Command'等。

a1.sources.tailsource-1.type = exec
a1.sources.tailsource-1.shell = /bin/bash -c
a1.sources.tailsource-1.command = for i in /path/*.txt; do cat $i; done

二、实现

2.1、配置文件

[root@master apache-flume-1.6.0-bin]# cat testconf/f1.propreties 
a1.sources = r1
a1.sinks = k1
a1.channels = c1

# Describe/configure the source
//使用exec source type属性为exec
a1.sources.r1.type=exec
//执行的命令是tail -f /opt/abc.log
a1.sources.r1.command=tail -f /opt/abc.log

# Describe the sink
a1.sinks.k1.type = org.apache.flume.sink.kafka.KafkaSink  
a1.sinks.k1.topic = testflume  
a1.sinks.k1.brokerList = master:9092,slave1:9092,slave2:9092  
a1.sinks.k1.requiredAcks = 1  
a1.sinks.k1.batchSize = 20  

# Use a channel which buffers events in memory
a1.channels.c1.type = memory
a1.channels.c1.capacity = 1000000
a1.channels.c1.transactionCapacity = 10000

# Bind the source and sink to the channel
a1.sources.r1.channels = c1
a1.sinks.k1.channel = c1

2.2、在kafka启动一个消费者

./bin/kafka-console-consumer.sh
--zookeeper master:3384,slave1:3384,slave2:3384
--from-beginning -topic testflume

2.3、启动flume

flume-ng

bin/flume-ng agent 
--conf /opt/apache-flume-1.6.0-bin/conf/ 
--conf-file ./testconf/f1.properties  
--name a1 
-Dflume.root.logger=INFO,console
-Dorg.apache.flume.log.printconfig=true 
-Dorg.apache.flume.log.rawdata=true

2.4、向/opt/abc.log中写数据,

for k in {1..10}
do
echo "现在插入的是第"$k"个数" >> /opt/abc.log
done

2.5、kafka消费者监听的

消费的数据正确
这里写图片描述

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值