flume架构

时间:2021-10-11
本文章向大家介绍flume架构,主要包括flume架构使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。

Flume介绍

Flume是Cloudera 开发的框架,它是用来进行数据和日志的收集工具,它采用的是实时的收集数据(比如:一号店,美团等都用Flume)。组合的架构一般有Kafka/flume + storm / spark streaming

Flume的分布式概念

我可以收集很多服务器上的日志,每个服务器都要运行一个Flume去收集,因为日志文件不可能在一台机器上。

Flume特点

Flume是用Java语言编写的,所以要用JVM环境

Flume仅仅支持Linux系统

Flume比较灵活,是因为我们只需要配置一个配置文件就可以,在配置文件中可以随便设置

Flume架构

Web Server(相当于云端):存放日志

Agent:

Source从WebServer中拿数据,放到一个管道里面,数据的单元叫Event(事件),也就是说source拿到数据之后封装成Event,放到管道当中,然后给Sink,然后Sink写到HDFS上或者是其他的source。

Channel:就是保证数据的安全性和完整性,起到一个缓冲的作用。

Event:包括两个部分:header和载有数据的byte array

header会携带一些信息:例如Flume每天收集的数据放到一个目录下,不可能一次创建所有的目录,可以通过服务器端的时间,把这个时间放到header里面,然后传递到Sink端,给我创建一个目录,然后把当天的数据放到这个目录下

数据流:

Flume使用要求

* 运行在有日志的地方

* 系统:Linux

* JVM/JDK

* 轻量级的服务(eg:zk,zkfc,sqoop)对硬件的要求不高

Flume安装部署

bin/flume-ng

Usage: bin/flume-ng <command> [options]...

commands:

  agent                     run a Flume agent

global options:(全局的参数)

  --conf,-c <conf>          use configs in <conf> directory(指定一个配置文件)

  -Dproperty=value          sets a Java system property value(指定一些属性的值)

agent options:

  --name,-n <name>          the name of this agent (required)

  --conf-file,-f <file>     specify a config file (required if -z missing)

>>>>>>>>>>>>>>>>>>如何使用>>>>>>>>>>>>>>>>>>>>>

bin/flume-ng agent \

--conf conf \

--name agent-test \

--conf-file test.conf \

bin/flume-ng agent

-c conf \

-n agent-test \

-f test.conf \

Flume使用案例

Flume案例1:

数据来源:netcat

接收数据:source...

写配置文件a1.conf内容如下

### define agent

a1.sources = r1

a1.channels = c1

a1.sinks = k1

###define sources

a1.sources.r1.type = netcat

a1.sources.r1.bind = master

a1.sources.r1.port = 44444

###define channels

a1.channels.c1.type = memory

a1.channels.c1.capacity  =  1000

a1.channels.c1.transactionCapacity  =  100

###define sink

a1.sinks.k1.type = logger

a1.sinks.k1.maxBytesToLog = 1024

### bind the sources and sink to the channel

a1.sources.r1.channels = c1

a1.sinks.k1.channel = c1

运行:

装一个软件telnet

yum install -y telnet

yum install -y telnet-server

启动Flume

bin/flume-ng agent -c conf -n a1 -f conf/a1.conf -Dflume.root.logger=DEBUG,console

启动telnet

telnet master 44444

Flume常用source、channle、sink

常用的source

Ecec Source (执行 source)

Spooling Directory Source(重点):监控一个目录,进行抽取数据

Syslog Source(收集系统日志)

HTTP Source

常用的channles

Memory Channle

JDBC Channle

Kafka Channel

File Channel

常用的Sinks

HDFS Sink

Hive Sink

Logger Sink

HBase Sink

ElasticSearchSink(es)

MorphlineSolrSink

Flume案例2:

收集log

hive运行的日志

日志目录:/tmp/lan

通过命令获取:tail -f 日志文件

 hdfs

收集后的存放位置:/user/lan/flume/hive-logs/

agent程序:实时监控读取的日志数据,存储hdfs文件系统

### define agent

a2.sources = r2

a2.channels = c2

a2.sinks = k2

###define sources

a2.sources.r2.type = exec

a2.sources.r2.command = tail -f /tmp/lan/hive.log

a2.sources.r2.shell = /bin/bash -c

###define channels

a2.channels.c2.type = memory

a2.channels.c2.capacity  =  1000

a2.channels.c2.transactionCapacity  =  100

###define sink

a2.sinks.k2.type = hdfs

a2.sinks.k2.hdfs.path =hdfs://master:9000/user/lan/flume/hive-logs/

a2.sinks.k2.hdfs.fileType = DataStream

a2.sinks.k2.hdfs.writeFormat = Text

a2.sinks.k2.hdfs.batchSize = 10

### bind the sources and sink to the channel

a2.sources.r2.channels = c2

a2.sinks.k2.channel = c2

运行命令

bin/flume-ng agent -c conf -n a2 -f conf/flume-tail.conf -Dflume.root.logger=DEBUG,console

原文地址:https://www.cnblogs.com/bsxc2/p/15393984.html