flume介绍与测试

背景

flume最开始由cloudera软件公司产出的可分布式日志收集系统,后于2009年被捐赠了apache软件基金会,为hadoop相关组件之一。不断的完善与版本升级,推出了flume-ng,现在早已是Apache顶级项目之一。

flume简介

Flume is a distributed, reliable, and available service for efficiently collecting, aggregating, and moving large amounts of log data. It has a simple and flexible architecture based on streaming data flows. It is robust and fault tolerant with tunable reliability mechanisms and many failover and recovery mechanisms. It uses a simple extensible data model that allows for online analytic application.
apache Flume 是一个对大量日志进行有效收集,汇总,转移的分布式服务,它具有高可用性和可靠性,flume简单灵活的体系结构基于流媒体数据流,同时,它具有健壮的、容错的,具有可调的可靠性机制和许多故障转移和恢复机制。它使用一个简单的可扩展的数据模型,允许联机分析应用程序。

数据流模型

flume event

事件作为Flume内部数据传输的最基本单元.它是由一个转载数据的字节数组(该数据组是从数据源接入点传入,并传输给传输器,也就是HDFS/HBase)和一个可选头部构成.

典型的Flume 事件如下面结构所示:

flume source在接受到数据之后,就需要根据不同设置将输入数据转换为event,同理,sink拿到数据之后也需要对event进行解析,然后再做后续操作。比如自定义一个flume-hbase-sink插件,获取的就是event然后对其解析,并依据情况做过滤等,然后在传输给HBase或者HDFS等。

Flume Agent

A Flume agent is a (JVM) process that hosts the components through which events flow from an external source to the next destination (hop).

flume agent就是一个JVM进程,它从外部源或者其他agent获得events,然后迅速传递给下一个agent或者其他服务。
agent基本模型:

可以看到,agent由三个组件组成,source,channel,sink。

  • Source:从数据发生器接收数据,并将接收的数据以Flume的event格式传递给一个或者多个通道channal,Flume提供多种数据接收的方式,比如Avro,Thrift,twitter1%等
  • Channel: channal是一种短暂的存储容器,它将从source处接收到的event格式的数据缓存起来,直到它们被sinks消费掉,它在source和sink间起着一共桥梁的作用,channal是一个完整的事务,这一点保证了数据在收发的时候的一致性. 并且它可以和任意数量的source和sink链接. 支持的类型有: JDBC channel , File System channel , Memort channel等.
  • sink: sink将数据存储到集中存储器比如Hbase和HDFS,它从channals消费数据(events)并将其传递给目标地. 目标地可能是另一个sink,也可能HDFS,HBase.
multi-agent flow

flume 支持多agent模型,即多个agent串联在一起使用,保证前一个agent的sink与后一个agent的source属性一致即可。

Multiplexing the flow

flume还支持多channel,多sink模式,在同一个agent中可以配置多个sink,注意的是一个sink只与一个channel相连。

  • 单source多channel(这个官网给的模型)

  • 多source单channel
    测试:

a1.sources = r1 r2
a1.sinks = k1
a1.channels = c1
# Describe/configure the source

a1.sources.r1.type = netcat
a1.sources.r1.bind = 10.0.13.72
a1.sources.r1.port = 44444

a1.sources.r2.type = netcat
a1.sources.r2.bind = 10.0.13.72
a1.sources.r2.port = 55555

# Describe the sink
a1.sinks.k1.type = logger

# 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.sources.r2.channels = c1
a1.sinks.k1.channel = c1

启动agent后,分别向44444端口和55555端口发送数据。

可以看到agent都接收到了数据。

  • 多channel单sink
a1.sources = r1 r2
a1.sinks = k1
a1.channels = c1 c2

# Describe/configure the source
 a1.sources.r1.type = netcat
 a1.sources.r1.bind = 10.0.13.72
 a1.sources.r1.port = 44444

 a1.sources.r2.type = netcat
 a1.sources.r2.bind = 10.0.13.72
 a1.sources.r2.port = 55555
 # Describe the sink
 a1.sinks.k1.type = logger

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

 a1.channels.c2.type = memory
 a1.channels.c2.capacity = 1000
 a1.channels.c2.transactionCapacity = 100
 # Bind the source and sink to the channel
 a1.sources.r1.channels = c1
 a1.sources.r2.channels = c2
 a1.sinks.k1.channel = c1 c2

启动。发现报错

但是端口正常启动

很明显,向端口发送数据后,flume并没有显示出来。

其实,仔细想想,这种模式并没有什么生产意义,算我瞎捣鼓吧。

  • 至于单source多channel,和单channel多sink,flume都是支持的,这个就不测试了,官网有例子。
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值