Flume基础

2018-08-10  本文已影响0人  糊涂蟲

1、产生背景

RDBMS==>Sqoop==>Hadoop

日志:分数在各个服务器上  如何抽到HDFS上

1、定时任务将文件写到HDFS    crontab

2、flume

2、官网

flume.apache.org

Flume是一种分布式、可靠和可用的服务,可以高效地收集、聚合和移动大量的日志数据。它具有基于流数据流的简单灵活的体系结构。它具有稳定性和容错性,具有可调的可靠性机制和多种故障转移和恢复机制。它使用了一个简单的、可扩展的数据模型,允许在线分析应用程序。

3、关键字

collecting            采集       source

aggregating        聚合       channel (找个地方把采集过来的数据暂存下)

moving               移动       sink

4、功能

Flume:编写配置文件,组合source、channel、sink三者之间的关系

Agent:就是由source、channel、sink组成

编写flume的配置文件其实就是配置agent的构成

Flume就是一个框架:针对日志数据进行采集汇总,把日志从A地方搬运到B地方去

5、系统要求

1、java1.6以上

2、足够内存(source,sink,channel都可能用)

3、足够的磁盘空间

4、对文件要有读写权限

6、环境搭建

文档:官网-->documentation-->Flume User Guide

版本:cdh5.7.0(与Hadoop统一)

wget http://archive.cloudera.com/cdh5/cdh/5/flume-ng-1.6.0-cdh5.7.0.tar.gz

解压

tar -xzvf flume-ng-1.6.0-cdh5.7.0.tar.gz -C ~/app

配置环境变量并生效   

vi ~/.bash_profile

export FLUME_HOME=/home/hadoop/app/apache-flume-1.6.0-cdh5.7.0-bin

export PATH=$FLUME_HOME/bin:$PATH

source ~/.bash_profile

修改配置文件

cp flume-env.sh.template flume-env.sh

vi flume-env.sh

export JAVA_HOME=/usr/java/jdk1.8.0_45

7、版本

flume -og        老版本,已经不用

flume -ng        新版本

8、运行

flume-ng  <commad> [options]...

常用的commads:help / agent / avro-client / version

举例:[hadoop@hadoop000 bin]$ flume-ng version

            Flume 1.6.0-cdh5.7.0

            Source code repository: https://git-wip-us.apache.org/repos/asf/flume.git

            Revision: 8f5f5143ae30802fe79f9ab96f893e6c54a105d1

            Compiled by jenkins on Wed Mar 23 11:38:48 PDT 2016

            From source with checksum 50b533f0ffc32db9246405ac4431872e

9、启动命令标准的写法

        ./flume-ng agent \                    ===>启动命令

        --name $agent_name \            ===>自定义的agent_name

        --conf $FLUME_HOME/conf \        ===>使用conf目录下一个配置文件:全局

        --conf-file /home/hadoop/script/flume/xxxx.conf \        ==>指定一个配置文件(自己编写的agent的配置文件:自定义)

        -Dflume.root.logger=INFO,console \

        -Dflume.monitoring.type=http \    

        -Dflume.monitoring.port=34343

9、agent_xxx.conf 的写法

agent_name:a1

r1、k1、c1分别为source、sink和channel的名称

# Name the components on this agent

复数表示每一个可以配多个

<agent_name>.sources=<source_name>        

<agent_name>.sinks=<sink_name>

<agent_name>.channels=<channel_name>

--------------------------------------------------------------------------------

<agent_name>.sources.<source_name>.type =xx

<agent_name>.sinks.<sink_name>.type =yyy

<agent_name>.channels.<channel_name>.type =zzz

-------------------------------------------------------------------------------------

<agent_name>.sources.<source_name>.channels=<channel_name>

<agent_name>.sinks.<sink_name>.channel=<channel_name>

--------------------------------------------------------------------------------------

举例:从指定的网络端口上采集日志到控制台输出(netcat source、memory channel 和logger  sink),需要telnet输入日志

        a1.sources = r1

        a1.sinks = k1

        a1.channels = c1

# Describe/configure the source   配置source信息

        a1.sources.r1.type = netcat     ==>必须netcat

        a1.sources.r1.bind = 0.0.0.0    ==>绑定本地ip

        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

# Bind the source and sink to the channel  将source和sink绑定到channel

        a1.sources.r1.channels = c1        ==>source 去哪个channel

        a1.sinks.k1.channel = c1            ==>sink去channel拿数据

10、常用的source

avro (重点):监听Avro端口和从外部Avro端接收事件流,当在另一个(上一个)Flume agent搭配内置Avro sink,它可以创建分层集合拓扑

exec  :启动的时候运行给定一个linux命令 tail -F  xx.log            ===>监控文件

Spooling Directory:允许通过将文件放入磁盘上的“spooling”目录中来读取数据               ===>监控文件夹(不能有子文件)

Taildir:exec 和spooling的整合  (生成90%以上)           1.6版本不能工作在windows

netcat: 可以监听给定的端口,并将每一行文本转换为一个事件   需要telnet

具体写法参考官网

11、常用的sink

HDFS:数据写到HDFS

logger:打印在控制台

avro : 配合avro source使用

kafka:(sparkstreaming或者 storm、 flink的流式处理当中)使用flume搜集数据推送到kafka,然后流式处理的数据到kafka中去取

12、常用的channel

memory:event将会被暂存在内存了

file:数据存到本地

13、agentxxx.conf作用

各种组合source、channel、sink之间的关系,需要什么去官网找什么

例如:把一个文件中新增的内容收集到HDFS

        exec ---memory ---HDFS    模式

如果是一个文件夹

        spooling---memory---HDFS    

文件数据写入kafka    

        exec---memory---kafka

以此类推。。。

14、Event

传输的最小单元

Event是有headers  +  body(字节数组  +  内容)组成

上一篇 下一篇

猜你喜欢

热点阅读