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:
morphlines : [
{
id : morphline1
# Import all morphline commands in these java packages and their subpackages.
# Other commands that may be present on the classpath are not visible to this morphline.
importCommands : ["org.kitesdk.**"]
commands : [
{
readLine {
charset : UTF-8
}
}
]
}
]
接下来是一个简单的flume.conf:
# Please paste flume.conf here. Example:
# Sources, channels, and sinks are defined per
# agent name, in this case 'tier1'.
tier1.sources = source1
tier1.channels = channel1
tier1.sinks = sink1
# For each source, channel, and sink, set
# standard properties.
tier1.sources.source1.type = netcat
tier1.sources.source1.bind = 0.0.0.0
tier1.sources.source1.port = 9999
tier1.sources.source1.channels = channel1
tier1.sources.source1.interceptors = morphlineinterceptor
tier1.sources.source1.interceptors.morphlineinterceptor.type = org.apache.flume.sink.solr.morphline.MorphlineInterceptor$Builder
tier1.sources.source1.interceptors.morphlineinterceptor.morphlineFile = /etc/flume-ng/conf/morphline.conf
tier1.sources.source1.interceptors.morphlineinterceptor.morphlineId = morphline1
tier1.channels.channel1.type = memory
tier1.sinks.sink1.type = logger
tier1.sinks.sink1.channel = channel1
# Other properties are specific to each type of
# source, channel, or sink. In this case, we
# specify the capacity of the memory channel.
tier1.channels.channel1.capacity = 100
接下来启动agent。
然后telnet localhost 9999,输入hello world回车。
在agent的日志文件中就可以看到如下日志信息: