Flume

Flume概述

Flume是一个高可用、高可靠、分布式的海量日志数据采集、聚合、传输的系统。Flume支持在日志系统中定制各类数据发送方,用于收集数据;同时,Flume提供对数据进行简单处理,并写到各种数据接收方的能力。

Flume(Agent,Java进程)主要由三个重要组件构成:

  • source,负责接收数据到flume agent的组件,数据输入常见类型avro,netcat
  • channel,缓冲区,自带两种channel,memory channel速度快,会丢失数据,file channel速度慢,不会丢失数据
  • sink,将channel数据取出到数据库,常见数据库hdfs,kafka,mysql

Flume的架构

除了上面三个组件还有以下几个核心概念:

  • Event:一个数据单元,分为Header和Body,消息头结构为kv,Body为字节数组
  • Agent:是一个JVM进程,将数据从源头传入目的,是Flume数据传输的基本单元,包含组件Source、Channel、Sink

Flume本地安装

  • 解压安装包
  • 更改配置文件flume-env.sh,添加JAVA_HOME变量

监控端口数据案例

使用Flume监控本机44444端口,通过telnet工具向端口44444发送数据,Flume将监听的数据实时显示在控制台。

1. 通过telnet工具向端口44444发送数据
telnet localhost 44444

2. 启动flume监听端口44444
bin/flume-ng agent --conf conf/ --name a1 --conf-file job/flume-telnet-logger.conf -Dflume.root.logger==INFO,console

3. 即可在控制台查看端口44444的数据
配置文件如下:
# Name the components on this agent
a1.sources = r1        //r1表示输入源
a1.sinks = k1          //k1表示输出源
a1.channels = c1       //c1表示缓冲区

# Describe/configure the source
a1.sources.r1.type = netcat         //输入类型
a1.sources.r1.bind = localhost      //输入源,本机
a1.sources.r1.port = 44444          //端口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

原文地址:https://www.cnblogs.com/chenshaowei/p/12604128.html