Flume 架构及部署

1.Flume概述

Flume是由 Cloudera 提供的一个分布式、高可靠、高可用的服务,用于分布式的海量日志的高效收集、聚合、移动系统。简单来说,Flume 就是一个针对日志数据进行采集和汇总的一个工具(把日志从A地方移动到B地方)

Flume 官网:http://flume.apache.org/
Flume 官方文档:http://flume.apache.org/FlumeUserGuide.html

Flume 特点:

(1).可靠性:当节点出现故障时,日志能够被传送到其他节点上而不会丢失。Flume提供了三种级别的可靠性保障,从强到弱依次分别为:

①.end-to-end(收到数据agent首先将event写到磁盘上,当数据传送成功后,再删除;如果数据发送失败,可以重新发送);
②.Store on failure(这也是scribe采用的策略,当数据接收方crash时,将数据写到本地,待恢复后,继续发送);
③.Best effort(数据发送到接收方后,不会进行确认)。

(2).可扩展性:Flume采用了三层架构,分别为agent,collector和storage,每一层均可以水平扩展所有agent和collector由master统一管理,这使得系统容易监控和维护,且master允许有多个(使用ZooKeeper进行管理和负载均衡),这就避免了单点故障问题。

(3).可管理性
①.所有agent和colletor由master统一管理,这使得系统便于维护。
②.多master情况,Flume利用ZooKeeper和gossip,保证动态配置数据的一致性。
③.用户可以在master上查看各个数据源或者数据流执行情况,且可以对各个数据源配置和动态加载。
④.Flume提供了web 和shell script command两种形式对数据流进行管理。①

(4).功能可扩展性
①.用户可以根据需要添加自己的agent,collector或者storage。
②.此外,Flume自带了很多组件,包括各种agent(file, syslog等),collector和storage(file,HDFS等)。

(5).文档丰富,社区活跃
Flume 是Apache下的一个顶级项目,已经成为 Hadoop 生态系统的标配,它的文档比较丰富,社区比较活跃,方便我们学习。

2.Flume 架构

这里写图片描述

Flume 架构介绍

      Flume 最简单的部署单元叫做Flume Agent,Agent 是一个Java 应用程序,接收或者生成数据并缓冲数据,直到最终写入到Agent或者存储或索引系统。

      一个Flume Agent可以连接一个或多个其它的Agent,一个Agent也可以从一个或多个Agent接收数据,通过相互连接的多个Flume Agent,一个流作业被建立,这个Flume Agent链条可以用于将数据从一个位置移动到另一个位置——特别是,从生产数据的应用程序到HDFS、HBase等。

每个Flume Agent有三个组件:Source、Channel、Sink

      Source 专门用来收集数据,可以处理各种类型、各种格式的日志数据,比如avro、exec、HTTP、Kafka、Spooling Directory等

      Channel 是一个存储Source已经接收到的数据的缓冲区,简单来说就是对Source采集到数据进行缓存,可以缓存在memory、file、jdbc、Kafka等。

      Sink 用于把数据发送到目的地,目的地可以是:HDFS、Hive、HBase、ES、Kafka、Logger等

Flume 运行机制

      flume的核心就是一个agent,这个agent对外有两个进行交互的地方,一个是接受数据的输入——source,一个是数据的输出sink,sink负责将数据发送到外部指定的目的地。source接收到数据之后,将数据发送给channel,chanel作为一个数据缓冲区会临时存放这些数据,随后sink会将channel中的数据发送到指定的地方—-例如HDFS等,注意:只有在sink将channel中的数据成功发送出去之后,channel才会将临时数据进行删除,这种机制保证了数据传输的可靠性与安全性

3.Flume 部署

目前Flume 的最新版本为1.8,笔者安装的是1.6,是Flume的一个经典版本,通常在生产环境中使用的就是这个版本,在安装Flume前,看先它的前置条件
(1).JDK1.7
(2).足够的内存
(3).足够的磁盘空间
(4).目录及文件要有读写权限

官网下载地址:http://archive.apache.org/dist/flume/
从官网下载,或者在linux中使用下面的命令下载,然后解压

$ wget http://archive.apache.org/dist/flume/1.6.0/apache-flume-1.6.0-bin.tar.gz
$ sudo tar -zxvf apache-flume-1.6.0-bin.tar.gz
$ sudo mv apache-flume-1.6.0-bin /opt/flume

flume 目录结构

这里写图片描述

配置flume

进入flume的conf目录下,拷贝flume-env.sh.template然后重命名为flume-env.sh

$ sudo cp flume-env.sh.template flume-env.sh

在flume-env.sh中配置jdk

export JAVA_HOME=/usr/java/jdk1.7.0

配置环境变量

# Flume Environment Variable
export FLUME_HOME=/opt/flume
export PATH=$PATH:$FLUME_HOME/bin

查看Flume 的命令帮助

[hadoop@Master ~]$ flume-ng help
Usage: /opt/flume/bin/flume-ng <command> [options]...

commands:
  help                      display this help text
  agent                     run a Flume agent
  avro-client               run an avro Flume client
  version                   show Flume version info

global options:
  --conf,-c <conf>          use configs in <conf> directory
  --classpath,-C <cp>       append to the classpath
  --dryrun,-d               do not actually start Flume, just print the command
  --plugins-path <dirs>     colon-separated list of plugins.d directories. See the
                            plugins.d section in the user guide for more details.
                            Default: $FLUME_HOME/plugins.d
  -Dproperty=value          sets a Java system property value
  -Xproperty=value          sets a Java -X option

agent options:
  --name,-n <name>          the name of this agent (required)
  --conf-file,-f <file>     specify a config file (required if -z missing)
  --zkConnString,-z <str>   specify the ZooKeeper connection to use (required if -f missing)
  --zkBasePath,-p <path>    specify the base path in ZooKeeper for agent configs
  --no-reload-conf          do not reload config file if changed
  --help,-h                 display help text

avro-client options:
  --rpcProps,-P <file>   RPC client properties file with server connection params
  --host,-H <host>       hostname to which events will be sent
  --port,-p <port>       port of the avro source
  --dirname <dir>        directory to stream to avro source
  --filename,-F <file>   text file to stream to avro source (default: std input)
  --headerFile,-R <file> File containing event headers as key/value pairs on each new line
  --help,-h              display help text

  Either --rpcProps or both --host and --port must be specified.

Note that if <conf> directory is specified, then it is always included first
in the classpath.

查看Flume 版本信息

[hadoop@Master ~]$ flume-ng version
Flume 1.6.0
Source code repository: https://git-wip-us.apache.org/repos/asf/flume.git
Revision: 2561a23240a71ba20bf288c7c2cda88f443c2080
Compiled by hshreedharan on Mon May 11 11:15:44 PDT 2015
From source with checksum b29e416802ce9ece3269d34233baf43f

4.Flume 简单使用

需求:从网络端口接受数据,输出到控制台

Agent选型:netcat+source + memory channel + logger sink

Flume中最重要的就是Agent配置文件的编写,如何编写,官网都有说明,下面是官网提供的一个Agent配置文件模板

# example.conf: A single-node Flume configuration

# Name the components on this agent
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
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.sinks.k1.channel = c1

参照上述官网的配置,新建simple-example.conf文件,配置如下

# Name the components on this agent
simple-agent.sources = netcat-source
simple-agent.sinks = logger-sink
simple-agent.channels = memory-channel

# Describe/configure the source
simple-agent.sources.netcat-source.type = netcat
simple-agent.sources.netcat-source.bind = Master
simple-agent.sources.netcat-source.port = 44444

# Describe the sink
simple-agent.sinks.logger-sink.type = logger

# Use a channel which buffers events in memory
simple-agent.channels.memory-channel.type = memory

# Bind the source and sink to the channel
simple-agent.sources.netcat-source.channels = memory-channel
simple-agent.sinks.logger-sink.channel = memory-channel

配置完成后,输入如下命令来启动flume

flume-ng agent \
--conf $FLUME_HOME/conf \
--name simple-agent \
--conf-file $FLUME_HOME/config/simple-example.conf \
-Dflume.root.logger=INFO,console

参数说明:
–conf:指定flume的配置文件所在目录
–name:指定Agent的名称
–conf-file:指定编写的flume配置文件
-Dflume.root.logger:指定日志级别

flume启动后,打印的日志中可以看到如下信息(部分日志)

Creating instance of source netcat-source, type netcat
Creating instance of sink: logger-sink, type: logger
Creating instance of channel memory-channel type memory
Created serverSocket:sun.nio.ch.ServerSocketChannelImpl[/192.168.242.150:44444]

输入jps命令可以查看到一个Application的进程,如果有这个进程,说明我们的flume启动成功了

[hadoop@Master ~]$ jps
3091 Jps
2806 Application
[hadoop@Master ~]$ jps -m
2806 Application --name simple-agent --conf-file /opt/flume/config/simple-example.conf
3101 Jps -m

测试(启动一个telnet进程,telnet 数据输入)

$ telnet Master 44444

这里写图片描述

查看Flume控制台的输出(Event是Flume数据传输的基本单元,由可选的header和一个byte array的数据构成)

Event: { headers:{} body: 68 65 6C 6C 6F 0D            hello. }
Event: { headers:{} body: 66 6C 75 6D 65 0D            flume. }
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值