@songlaf
2016-06-02T18:34:02.000000Z
字数 1548
阅读 558
北风网大数据培训
Flume是一个分布式、可靠、和高可用的海量日志聚合的系统,支持在系统中定制各类数据发送方,用于收集数据;同时,Flume提供对数据进行简单处理,并写到各种数据接受方(可定制)的能力。
基本架构如下:
Flume以agent为最小的独立运行单位。一个agent就是一个JVM。每个agent由Source、Sink和Channel三大组件构成。
角色 | 简介 |
---|---|
Source | 数据的来源,可能是RDMS,也可能是文件,flumen可以监控文件 |
Channel | 链接Source和sinks |
Sink | 从Channel收集数据,写入目标源,可能是HDFS,也可能是Hbase。 |
备注1:
Flume提供了大量内置的Source、Channel和Sink类型。不同类型的Source,Channel和Sink可以自由组合。组合方式基于用户设置的配置文件,非常灵活。比如:Channel可以把事件暂存在内存里,也可以持久化到本地硬盘上。Sink可以把日志写入HDFS, HBase,甚至是另外一个Source等等。
Flume支持用户建立多级流,也就是说,多个agent可以协同工作,并且支持Fan-in、Fan-out、Contextual Routing、Backup Routes.
备注2:
Event是Flume的基本数据单位,event由header和一本byte array组成,Event由Agent外部的Source生成。当Source捕获事件后会进行特定的格式化,然后Source会把事件推入(单个或多个)Channel中。Channel是一个先进先出的队列,sink主动屈从channel中拉去数据,然后再写入目标源。
修改配置文件conf/lume-env.sh
增加java的配置
export JAVA_HOME=/opt/modules/jdk1.7.0_67
新建一个配置文件
# 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 = njt.song.s0 #注意要在host文件有这个地址
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
运行flumen
bin/flume-ng agent --conf conf --conf-file conf/example.conf --name a1 -Dflume.root.logger=INFO,console
#-c/--conf 后跟配置目录,-f/--conf-file 后跟具体的配置文件,-n/--name 指定agent的名称
#在前面nohup可以提交到后台进行
运行:
telnet njt.song.s0 44444
执行结果: