美文网首页
Hadoop学习笔记(3)-Flume

Hadoop学习笔记(3)-Flume

作者: 丸蛋蟹 | 来源:发表于2017-03-17 15:11 被阅读89次

自行整理, 学习用途, 侵知删歉
Flume的设计目标: 可靠性, 可量测性, 可扩展性

高层架构

Agent将数据写成多种HDFS文件格式(text, SeqFile, JSON, Avro).
Source: 告诉节点从哪里接受数据
Sink: 告诉节点把数据发送到哪里去
Channel: Source和Sink之间的序列, 可以放在内存或者可持续化, 持续化的掉电后不失去数据[可放入硬盘]

  • 向下agent传送失败会回滚, 然后重试; 多台agent向上传输数据如果其中一台失败会切换
  • Flume的性能随着机器的增加会线性的增加

扩展性:

Source: 包括文件数据, 系统log, 标准linux process输出
Sink: 包括本地文件系统的文件, 或者HDFS
开发者还能自己设计Source Sink


典型结构

逻辑分层

Flume采用了分层架构:分别为agent,collector和storage。

agent

agent的作用是将数据源的数据发送给collector。
Flume自带了很多直接可用的数据源
source

text(“filename”):将文件filename作为数据源,按行发送
tail(“filename”):探测filename新产生的数据,按行发送出去
fsyslogTcp(5140):监听TCP的5140端口,并且接收到的数据发送出去
tailDir("dirname"[, fileregex=".*"[, startFromEnd=false[, recurseDepth=0]]]):监听目录中的文件末尾,使用正则去选定需要监听的文件(不包含目录),recurseDepth为递归监听其下子目录的深度

更多整理:http://www.cnblogs.com/zhangmiao-chp/archive/2011/05/18/2050465.html

sink

console[("format")] :直接将将数据显示在consolr上
text(“txtfile”):将数据写到文件txtfile中
dfs(“dfsfile”):将数据写到HDFS上的dfsfile文件中
syslogTcp(“host”,port):将数据通过TCP传递给host节点
agentSink[("machine"[,port])]:等价于agentE2ESink,如果省略,machine参数,默认使用flume.collector.event.host与flume.collector.event.port作为默认collecotr
agentDFOSink[("machine" [,port])]:本地热备agent,agent发现collector节点故障后,不断检查collector的存活状态以便重新发送event,在此间产生的数据将缓存到本地磁盘中
agentBESink[("machine"[,port])]:不负责的agent,如果collector故障,将不做任何处理,它发送的数据也将被直接丢弃
agentE2EChain:指定多个collector提高可用性。 当向主collector发送event失效后,转向第二个collector发送,当所有的collector失败后,它会非常执着的再来一遍

更多整理:http://www.cnblogs.com/zhangmiao-chp/archive/2011/05/18/2050472.html

collector

collector的作用是将多个agent的数据汇总后,加载到storage中。
它的source和sink与agent类似


安装, 配置, 启动Flume

安装:

-sudo yum install flume-ng
-sudo yum install flume-ng-agent

配置产生数据的Agent节点:
/etc/flume-ng/conf/flume-conf.properties文件决定了source,sinks,channels以及agent内的flow

启动:

#启动一个host上的单个Flume agent
sudo service flume-ng-agent start 
#启动一个host上的多个Flume agent
flume-ng --name <agent_name>

运行实例

1.安装

$ sudo yum install --assumeyes flume-ng

2. 创建配置文件excample.conf

# 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 = 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

3. 终端(A)启动Agent

$ flume-ng agent \
 -c conf \
 -f /opt/wanghaixin/01.flume/example.conf \
-n a1 \
-Dflume.root.logger=INFO,console

4. 开启另一个终端(B)通过telnet对端口44444注入内容, 充当source

$ telnet localhost 44444
#接着可以键盘输入, 如输入 :hhhhh

5. 在终端(A)可观察到打印

$ hadoop fs -ls flume/collector1

更多资料:

http://flume.apache.org/FlumeUserGuide.html
http://www.cnblogs.com/oubo/archive/2012/05/25/2517751.html

相关文章

网友评论

      本文标题:Hadoop学习笔记(3)-Flume

      本文链接:https://www.haomeiwen.com/subject/dgrfnttx.html