您的位置:首页 > 其它

Flume学习笔记之初识(一)

2016-09-27 10:08 363 查看

一、 基本概念

引入:

Flume是一个分布式的,可靠的,高可用的海量日志采集、聚合、传输的系统。

数据流模型:source-channel-sink + topology (图1)

事务机制保障了消息传递的可靠性。

有丰富的插件,可以轻松的与其他系统集成。

java实现,适合我们java系程序员研究源代码。



(图1)例子:使用Flume将Nginx Log、Scribe、Kafka数据导入HDFS

基本概念:

Flume基本组件 (图2)

• Event:消息的基本单位,由headers和body组成

• Agent:JVM进程,负责将外部来源产生的消息转发到外部的目

的地

• Source:从外部来源读入event,并写入channel

• Channel:event暂存组件,source写入后,event将会一直

保存,直到被sink成功消费。

• Sink:从channel读入event,并写入目的地



(图2)Flume数据流模型

常见的拓扑结构:

1 聚合模型:



2 分流模型:



二、环境搭建

有两种搭建方式:

1. 下载二进制压缩包

• 下载地址:http://flume.apache.org/download.html

2. 编译源码

• gihub地址:git@github.com:apache/flume.git

• maven编译:mvn clean install -DskipTests -Phadoop-2

一个简单的例子(Hello World)

创建conf/example.conf

# name the component on agent a1 ,can name mulity source,sink or channel
a1.sources = r1
a1.sinks = k1
a1.channels = c1

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

# describe the sink, k1 will print message on console
a1.sinks.k1.type = logger

# configure the channel, c1 is a memery channel
a1.channels.c1.type = memory
a1.channels.c1.capacity = 1000
a1.channels.c1.transactionCapacity=100

# bind the source and sink to the channel

# a sources can have sevel channels
a1.sources.r1.channels = c1

# a sink can have only one channel
a1.sinks.k1.channel = c1


启动agent:bin/flume-ng agent –conf conf –conf-file conf/helloword.conf –name a1 -Dflume.root.logger=INFO,console

–conf 指定配置文件的根目录,flume可从这个目录读入一些env,log4j等配置。–conf-file指定配置文件,–name 指定agent name,-Dxxx 指定额外配置参数。

3 向44444端口发送Hello World



通过telnet发送Hello World。

Flume接收到HelloWorld

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  Flume