flume学习(九):使用Morphline Interceptor

Morphline是干嘛用的?简单点说就是一个ETL工具,详细介绍:http://kitesdk.org/docs/current/kite-morphlines/morphlinesReferenceGuide.html

这里有一个注意点,是和cloudera search版本有关系的,我是用CDH 5.0.0, Parcel搭建的集群环境,对应装的cloudera search是1.0版本的,这个版本用的是kitesdk的morphlines,如果是更高版本的比如search1.3,可能用的就是cdk的morphlines了。用的哪个development kit对morphlines配置文件里面的那个 importCommands 配置是有讲究的,我用的kitesdk,所以应该写为: importCommands : ["org.kitesdk.**"],如果用的cdk的,则应该写为 importCommands : ["com.cloudera.**"],否则将无法导入commands。

还有一个小插曲就是,在研究flume-ng使用morphlines的过程中,每次启动agent都卡在importing commands上,不一会agent就挂掉了,这个问题纠结了很久,开始以为是search的相关jar包没有加载到classpath中去,导致无法导入commands,后面讲search的相关jar包都扔到flume的plugins.d插件目录下面了,还是不行。查看日志也没发现什么特别的异常,无意中发现了一个oom的异常,于是将agent的jvm调大为512M(cm装完默认agent的jvm只有50M),再重新启动agent,终于成功导入了commands,哎CM坑爹的默认配置折腾了我两天时间,不过还是研究各种官方文档学到了一些其他的知识,还是值得的。

下面贴出一个很简单的morphline.conf:

[plain]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. morphlines : [  
  2.   {  
  3.     id : morphline1  
  4.   
  5.     # Import all morphline commands in these java packages and their subpackages.  
  6.     # Other commands that may be present on the classpath are not visible to this morphline.  
  7.     importCommands : ["org.kitesdk.**"]  
  8.   
  9.     commands : [  
  10.         {  
  11.                  readLine {  
  12.                         charset : UTF-8  
  13.                  }  
  14.         }  
  15.     ]  
  16.   }  
  17. ]  

只定义了一个kitesdk的一个command叫readLine(具体用法和解释参见:http://kitesdk.org/docs/current/kite-morphlines/morphlinesReferenceGuide.html),就是会将输入一行一行的读取,然后存放到一个叫message的键当中去。

接下来是一个简单的flume.conf:

[plain]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. # Please paste flume.conf here. Example:  
  2.   
  3. # Sources, channels, and sinks are defined per  
  4. # agent name, in this case 'tier1'.  
  5. tier1.sources  = source1  
  6. tier1.channels = channel1  
  7. tier1.sinks    = sink1  
  8.   
  9. # For each source, channel, and sink, set  
  10. # standard properties.  
  11. tier1.sources.source1.type     = netcat  
  12. tier1.sources.source1.bind     = 0.0.0.0  
  13. tier1.sources.source1.port     = 9999  
  14. tier1.sources.source1.channels = channel1  
  15. tier1.sources.source1.interceptors = morphlineinterceptor  
  16. tier1.sources.source1.interceptors.morphlineinterceptor.type = org.apache.flume.sink.solr.morphline.MorphlineInterceptor$Builder  
  17. tier1.sources.source1.interceptors.morphlineinterceptor.morphlineFile = /etc/flume-ng/conf/morphline.conf  
  18. tier1.sources.source1.interceptors.morphlineinterceptor.morphlineId = morphline1  
  19.   
  20. tier1.channels.channel1.type   = memory  
  21. tier1.sinks.sink1.type         = logger  
  22. tier1.sinks.sink1.channel      = channel1  
  23.   
  24. # Other properties are specific to each type of  
  25. # source, channel, or sink. In this case, we  
  26. # specify the capacity of the memory channel.  
  27. tier1.channels.channel1.capacity = 100  

morphline interceptor的配置我直接摘自官方文档,主要注意一下那个morphlineFile就行了,把上面那个morphline.conf放到/etc/flume-ng/conf目录下面,morphlineId可以指定一个ID(如果morphline.conf中有配置多个ID的话)

接下来启动agent。

然后telnet localhost 9999,输入hello world回车。

在agent的日志文件中就可以看到如下日志信息:

Event: { headers:{message=hello world} body: }
注意这个message属性是添加到了event的headers当中了。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值