Flume NG 学习笔记(二)单机与集群Flume 配置
来源:互联网 发布:java和c哪个前景好2017 编辑:程序博客网 时间:2024/06/07 09:28
下面的内容基本来自官网:http://flume.apache.org/FlumeUserGuide.html英语好的就不用看我这里来。。。
本文使用的是最新版本的apache flume 1.5,安装完Flume然后测试下Flume是否可以用,在Flume目录下用以下语句测试:
bin/flume-ng agent -n$agent_name -c conf -f conf/flume-conf.properties.template
结果如图显示:
Ok,我们接下去看下面常用架构、功能配置示例
一、最简单的单一代理Flume 配置
下面是配置文件:
#文件名:single_case1.conf.conf#配置内容:#single_case1.conf.conf: A single-node Flume configuration#Name the components on this agenta1.sources= r1a1.sinks= k1a1.channels= c1 #Describe/configure the sourcea1.sources.r1.type= netcata1.sources.r1.bind= localhosta1.sources.r1.port= 44444 #Describe the sinka1.sinks.k1.type= logger #Use a channel which buffers events in memorya1.channels.c1.type= memorya1.channels.c1.capacity= 1000a1.channels.c1.transactionCapacity= 100 #Bind the source and sink to the channela1.sources.r1.channels= c1a1.sinks.k1.channel= c1
说明下,这里所有的例子都是将配置文件放到 $FLUME_HOME/conf 目录下,后面就不赘述了。
#敲命令
flume-ng agent -cconf -f conf/single_case1.conf -n a1 -Dflume.root.logger=INFO,console
#参数命令
-c conf 指定配置目录为conf
-f conf/single_case1.conf指定配置文件为conf/single_case1.conf
-n a1 指定agent名字为a1,需要与case1_example.conf中的一致
-Dflume.root.logger=INFO,console指定DEBUF模式在console输出INFO信息
具体参数命令请通过flume-nghelp查看
#然后在另一个终端进行测试
telnet 127.0.0.1 44444
然后会看在之前启动的终端查看console输出到如下:
这里会发现消息hello world! 输出了,而hello world! hello world!hello world!则被拦截了。因为在配置文件中,我们选择的输出方式为:a1.sinks.k1.type= logger
,即console输出,flume-ng针对logger是只显示16个字节的,剩下的都被sink截了。下面是源码
在LoggerSink.java中:
if(event != null) { if (logger.isInfoEnabled()) { logger.info("Event: " + EventHelper.dumpEvent(event)); }}
我们去看EventHelper.java的dumpEvent方法:
privatestatic final int DEFAULT_MAX_BYTES = 16;publicstatic String dumpEvent(Event event) { return dumpEvent(event, DEFAULT_MAX_BYTES);} publicstatic String dumpEvent(Event event, int maxBytes) { StringBuilder buffer = new StringBuilder(); if (event == null || event.getBody() == null) { buffer.append("null"); } else if (event.getBody().length == 0) { // do nothing... in this case, HexDump.dump() will throw anexception } else { byte[] body = event.getBody(); byte[] data = Arrays.copyOf(body, Math.min(body.length,maxBytes)); ByteArrayOutputStream out = new ByteArrayOutputStream(); try { HexDump.dump(data, 0, out, 0); String hexDump = new String(out.toByteArray()); // remove offset since it's not relevant for such a smalldataset if(hexDump.startsWith(HEXDUMP_OFFSET)) { hexDump =hexDump.substring(HEXDUMP_OFFSET.length()); } buffer.append(hexDump); } catch (Exception e) { if(LOGGER.isInfoEnabled()) { LOGGER.info("Exception while dumpingevent", e); } buffer.append("...Exception while dumping:").append(e.getMessage()); } String result = buffer.toString(); if(result.endsWith(EOL) && buffer.length() >EOL.length()) { buffer.delete(buffer.length() - EOL.length(),buffer.length()).toString(); } } return "{ headers:" + event.getHeaders() + " body:"+ buffer + " }"; }
不难看出,在event处理过程中,发生了数据截取操作。
Ok,进入下一个环节。
二、“集群”代理Flume 配置
这里集群的概念是多台机器的管理,最简单的就是两台机器一台代理主机从数据源获取数据,然后将数据在传送到另一台主机上,进行输出。这样做的意义是,一个业务多数据源的时候,我们可以对每个数据源设置代理,然后将它们汇总到一台代理主机上进行输出。
下面实现最简单的集群配置,即两个代理,一台接受数据源数据的代理将数据推送到汇总的代理,而汇总的代理再将数据输出。因此这两台主机分别是push,pull
根据上图需要用AVRO RPC通信,因此推数据sinks类型与拉数据的sources的类型都是avro 。而拉数据代理的数据源,我们用前文讲的Spool Source 形式来处理,这里我们预先建好目录与文件,test.log
下面设置推代理主机的flume配置文件:
#推数据代理的配置文件push.conf#Name the components on this agenta2.sources= r1a2.sinks= k1a2.channels= c1 #Describe/configure the sourcea2.sources.r1.type= spooldira2.sources.r1.spoolDir= /tmp/logsa2.sources.r1.channels= c1 #Use a channel which buffers events in memorya2.channels.c1.type= memorya2.channels.c1.keep-alive= 10a2.channels.c1.capacity= 100000a2.channels.c1.transactionCapacity= 100000 #Describe/configure the sourcea2.sinks.k1.type= avroa2.sinks.k1.channel= c1a2.sinks.k1.hostname= pulla2.sinks.k1.port= 4444
下面设置汇总代理主机的flume配置文件:
#汇总数据代理的配置文件pull.conf#Name the components on this agenta1.sources= r1a1.sinks= k1a1.channels= c1 #Describe/configure the sourcea1.sources.r1.type= avroa1.sources.r1.channels= c1a1.sources.r1.bind= pulla1.sources.r1.port= 44444 #Describe the sinka1.sinks.k1.type= logger a1.sinks.k1.channel = c1 #Use a channel which buffers events in memorya1.channels.c1.type= memorya1.channels.c1.keep-alive= 10a1.channels.c1.capacity= 100000a1.channels.c1.transactionCapacity= 100000
虽然Spool Source是非实时的,但由于数据量少,处理还是很快的,因此我们只能先启动pull代理。
#敲命令
flume-ng agent -c conf -f conf/pull.conf -n a1 -Dflume.root.logger=INFO,console
上图显示成功。
先后去启动push主机的flume
#敲命令
flume-ng agent -n a2 -c conf -f conf/push.conf -Dflume.root.logger=INFO,console
查看pull主机的状态,发现数据已经传过来了。
然后会过去看push主机的文件
已经加上后缀名.COMPLETED。这与前文说的是一致的。
下面只要将新数据存入到目录/tmp/logs,push主机就会将数据发送到pull主机输出,并修改新数据文件的文件名。
- Flume NG 学习笔记(二)单机与集群Flume 配置
- Flume NG 学习笔记(四)Source配置
- Flume NG 学习笔记(五)Sinks和Channel配置
- flume-ng demo单机配置详解
- Flume NG 学习笔记(一)简介
- Flume单机安装与配置
- Flume NG 配置详解
- Flume-ng配置
- Flume NG 配置
- Flume NG 配置详解
- Flume-ng配置
- 【Java】【Flume】Flume-NG启动过程源码分析(二)
- 【Java】【Flume】Flume-NG启动过程源码分析(二)
- Flume NG 学习笔记(三)流配置
- Flume NG 学习笔记(九)Flune Client 开发
- Flume-ng+Kafka+storm的学习笔记
- Flume-ng+Kafka+storm的学习笔记
- Flume-ng+Kafka+storm的学习笔记
- spring mvc 使用及json 日期转换解决方案
- java 方法调用过程遵循的原则
- 游戏数据保存的种类、区别和联系以及使用技巧以及脚本的用法
- oracle 如何查看日志
- jsp 传多个值给后端
- Flume NG 学习笔记(二)单机与集群Flume 配置
- iOS之多线程开发小结
- Python学习(一)python 入门
- 三步升级已安装的 Android SDK 和 ADT 插件
- 常用的webservice接口
- WdatePicker无法弹出日期框
- 二手笔记本中常见三叉插头以及英标欧标和美标的区别!
- Autodesk最新云及移动开发技术沙龙(上海站)11月10日
- Acronis Disk Director 增大c盘