source介绍及动手实践

flume内置了大量的source,其中avro source、thrift source、spooling directory source、kafka source具有较好的性能和较广泛的使用场景。

avro source
Avro Source监听Avro端口,接收外部Avro客户端发送过来的Avro Event数据。在多级流中,Avro Source可以和前一个Flume Agent的Avro Sink配对,建立分层收集拓扑。Avro Source的配置如下表所示,表中只列出必填项,即type、channels、bind、port
a1.sources = r1#a1中的Source
a1.channels = c1 #a1中的Channel 
a1.sources.r1.type = avro #Source的类型 
a1.sources.r1.channels = c1 #指定Source r1数据发送到的Channel 
a1.sources.r1.bind = 0.0.0.0#Source绑定的地址
a1.sources.r1.port = 4141#Source监听的端口

thrift source
Thrift Source监听Thrift端口,接收外部Thrift客户端发送过来的Thrift Event数据。在多级流中,Thrift Source可以和前一个Flume Agent的Thrift Sink配对,建立分层收集拓扑。Thrift Source支持基于Kerberos身份验证的安全模式。Thrift Source的配置如下表所示,表中只列出必填项,即type、channels、bind、port。Thrift Source支持基于Kerberos身份验证的安全模式。
a1.sources = r1#a1中的Source 
a1.channels = c1 #a1中的Channel 
a1.sources.r1.type = thrift #Source的类型
a1.sources.r1.channels = c1 #指定Source r1数据发送到的Channel 
a1.sources.r1.bind = 0.0.0.0#Source绑定的地址
a1.sources.r1.port = 4141#Source监听的端口

exec source
Exec Source在启动时调用的Unix命令,该命令进程会持续地把标准日志数据输出到Exec Source,如果命令进程关闭,Exec Source也会关闭。Exec Source支持cat [named pipe]或者tail -F [file]命令。Exec Source最大的问题就是数据有可能丢失,因为当Channel接收Exec Source数据出错时或者抛出异常时,Exec Client并不能捕获到该错误。建议使用Spooling Directory Source代替。表中只列出必填项,type、channels、command。
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

jms source
JMS Source从队列或者Topic中读取数据,目前只在ActiveMQ中测试。在使用JMS Source时,必须在Flume ClassPath中添加JMS JAR包
channels、type、initialContextFactory、connectionFactory、providerURL、destinationName、destinationType必填项。
a1.sources = r1 
a1.channels = c1 
a1.sources.r1.type = jms 
a1.sources.r1.channels = c1 
a1.sources.r1.initialContextFactory = org.apache.activemq.jndi.ActiveMQInitialContextFactory 
a1.sources.r1.connectionFactory = GenericConnectionFactory 
a1.sources.r1.providerURL = tcp://mqserver:61616 
a1.sources.r1.destinationName = BUSINESS_DATA 
a1.sources.r1.destinationType = QUEUE

spooling directory source
Spooling Directory Source监听系统上的指定目录,当目录中有新的文件创建时,Spooling Directory Source会把新文件的内容读取并推送到Channel中,并且把已读取的文件重命名成指定格式或者把文件删除。由于数据是以文件的形式存放的系统中,Spooling Directory Source的可靠性非常高,即使是Flume Agent崩溃或者重启,数据也可以恢复。channels、type、spoolDir为必填项
注意:
1、拷贝到spool指定的目录下的文件不可再打开编辑
2、spool目录下不可有子目录
a1.sources = s1 #a1中的Source 
a1.channels = c1 #a1中的Channel 
a1.sources.s1.type = spooldir #Source的类型 
a1.sources. s1.channels = c1 #指定Source r1数据发送到的Channel 
a1.sources. s1.spoolDir = /var/log/apache/flumeSpool
kafka source
Kafka Source从消息队列Kafka Topic中读取日志消息,Kafka Source相当于消息队列的Consumer。可以把多个Kafka Source配置到同一个分组里面,这样每个Source都可以读取同一个Topic中的数据,从而提高性能。channels、type、zookeeperConnect、groupId、topic为必填项
a1.sources.source1.type = org.apache.flume.source.kafka.KafkaSource
a1.sources.source1.channels = channel1
a1.sources.source1.zookeeperConnect = localhost:2181
a1.sources.source1.topic = test1
a1.sources.source1.groupId = flume
a1.sources.source1.kafka.consumer.timeout.ms = 100

netcat source
NetCat Source监听指定的端口,把接收到的数据按行划分,每行文本都封装成一个Event数据发送给Channel。type、bind、port为必填项a1.sources = r1 
a1.channels = c1 
a1.sources.r1.type = netcat 
a1.sources.r1.bind = 0.0.0.0
a1.sources.r1.bind = 6666 
a1.sources.r1.channels = c1

http source

HTTP Source接收POST和GET发送的Event数据,其中GET主要用户测试,不建议生产环境使用。HTTP数据通过handler(实现HTTPSourceHandler接口)转换成Event,该handler接收HttpServletRequest并返回Event数组。如果handler出现异常,HTTP Source返回400错误。如果Channel满了或者Channel无法接收Event,HTTP Source返回503错误。channels、type、port、org.apache.flume.source.http为必填项
a1.sources = r1 a1.channels = c1 a1.sources.r1.type = http a1.sources.r1.port = 5140 a1.sources.r1.channels = c1 a1.sources.r1.handler = org.example.rest.RestHandler a1.sources.r1.handler.nickname = random props


syslog source
读取syslog数据,并生成flume event,UDP source将整个消息作为一个单一的event,TCP source为每一个用回车来分隔的字符串创建一个新的事件
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章