Flume学习笔记之初识(一)

来源:互联网 发布:软件开发好学吗? 编辑:程序博客网 时间:2024/05/29 05:53

一、 基本概念

引入:
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)

  1. 创建conf/example.conf
# name the component on agent a1 ,can name mulity source,sink or channela1.sources = r1a1.sinks = k1a1.channels = c1# describe/configure the sourcea1.sources.r1.type = netcata1.sources.r1.bind = localhosta1.sources.r1.port = 44444# describe the sink, k1 will print message on consolea1.sinks.k1.type = logger# configure the channel, c1 is a memery channela1.channels.c1.type = memorya1.channels.c1.capacity = 1000a1.channels.c1.transactionCapacity=100# bind the source and sink to the channel  # a sources can have sevel channelsa1.sources.r1.channels = c1  # a sink can have only one channela1.sinks.k1.channel = c1
  1. 启动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
这里写图片描述

0 0
原创粉丝点击