flume学习整理
一、介绍
flume是分布式、可靠的、可用性好的服务,用于收集、聚合、异动大量日志数据,基于流计算的简单灵活框架,用于在线分析。
二、特点
-
优点
-
可以和任何集中式存储进行集成
-
输入数据速率大于写入存储目的地的速率时,flume会进行缓存。
-
flume提供上下文路由(数据流路线)
-
flume中的事务基于channel,使用了两个事务模型(sender,receive),确保消息被可靠发送
-
flume高效收集web server的log到hdfs
-
可以高效获取数据
-
导入大量数据
-
flume支持大量的source和destination类型
-
flume支持多级跳跃,source和destination的扇入和扇出
-
flume水平可扩展
-
-
put的问题
-
同一时刻只能传输一个文件
-
put处理静态文件
-
三、架构
-
描述 在数据生成器运行的节点上启动单独的flume agent,来收集数据,数据收集器收集数据,推送到hdfs
-
flume event 事件是flume的传输单元,主要是byte[],可以包含一些header信息,在source和destination之间
-
flume agent 每个agent是一个独立的java进程,从客户端(其他agent)接收数据,然后转发到下一个destination(sink/agent)
-
agent包含三个组件
-
source 源头 从事件生成器接收数据,以事件的形式,传给一个或多个channel
-
channel 通道 从source中接收flume event ,作为临时存放地,缓存到buffer,直到sink将其消费掉,是source和sink之间的桥梁,channel是事务的,可以和多个source和sink协同
-
sink 沉槽 存放数据到hdfs,从channel中消费event,并分发给destination,sink的destination也可以是另一个agent或者hdfs。 一个flume的agent可以有多个source,channel,sink
-
-
flume的附件组件
-
interceptor
-
channel selector
-
sink processors
-
四、安装
-
下载flume,apache-flume-1.6.0-src.tar.gz
-
tar -zxvf apache-flume-1.6.0-src.tar.gz
-
配置环境变量 profile
-
验证安装 flume-ng version
-
配置flume conf/ flume-env.sh 配置java_home
-
配置flume
-
命名agent组件
-
描述配置source
-
描述配置channel
-
描述配置sink
-
绑定source,sink到channel
-
五、使用
-
命令行模式 /flume.properites
# 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
-
运行flume agent flume-ng ag