[Flume]

Apache Flume是一个分布式的、可靠的、高效的系统,可以将不同来源的数据收集、聚合并移动到集中的数据存储中心上。Apache Flume不仅仅只是用到日志收集中。由于数据来源是可以定制的,flume可以使用传输大量的自定义event数据,包括但不限于网站流量信息、社会媒体信息、email信息以及其它可能的数据。Flume是Apache软件基金组织的顶级项目。官网http://flume.apache.org/.


一、安装

  flume提供了二进制安装版本,所有我们可以选择直接下载二进制安装版本,不用自己编译。下载地址http://flume.apache.org/download.html,也可以选择apache的归档库进行其他版本的下载,地址为http://archive.apache.org/dist/flume/。由于我们使用的是centos系统,直接使用命令下载软件并安装,安装完成后,可以选择将flume的bin目录添加到path环境变量中。

wget http://archive.apache.org/dist/flume/1.6.0/apache-flume-1.6.0-bin.tar.gz
解压
tar -zxvf apache-flume-1.6.0-bin.tar.gz
建立软连接
cd ..
ln -s softs/apache-flume-1.6.0-bin flume

二、一个简单的Flume例子

  在Flume1.X以后版本,进行了很大的结构更改,Flume主要组件为agent,分别由source、channel和sink组成。source的作用主要是收集外部数据,并将数据发送给channel。channel的主要作用是存储数据,作为一个数据流的通道。sink的作用主要是从channel中读取数据,并将数据发送给下一个agnet或者目的地。结构如图所示:

  这里采用一个最简单的例子,全部使用flume自带组件,分别使用avro source, memory channel,logger sink。实现功能为:avro监听端口44444,然后将数据发送给channel,sink读取数据后,将数据打印到控制台。

## example: a single-node flume configuration

# name the compoents on this agent
a1.sources=r1
a1.sinks=s1
a1.channels=c1

# describe/configure the source
a1.sources.r1.type=netcat
a1.sources.r1.bind=0.0.0.0
a1.sources.r1.port=44444

# describe/configure the sink
a1.sinks.s1.type=logger

# describe/configure the channel
a1.channels.c1.type=memory
a1.channels.c1.capacity=1000
a1.channels.c1.transactionCapacity=100

# bind all compoents of source and sink to channel
a1.sources.r1.channels=c1
a1.sinks.s1.channel=c1

  启动flume命令为:

bin/flume-ng agent -n a1 -f conf/flume-conf.properties

看见下图表示启动成功,或者你通过jps命令查看是否有Application进程,如果有表示成功。

  通过telnet来连接发送数据。命令为 telnet ip port。最终结果如图:

原文地址:https://www.cnblogs.com/liuming1992/p/4767071.html