色魔王子7 发表于 2017-12-24 20:23:13

Apache Flume 1.7.0 源码编译 导入Eclipse

前言
  最近看了看Apache Flume,在虚拟机里跑了一下flume + kafka + storm + mysql架构的demo,功能很简单,主要是用flume收集数据源(http上报信息),放入到kafka队列里,然后用storm消费kafka里的资源,计算结果并存入到mysql中;
  在这期间遇到了很多问题,也学到了一些知识,打算做个笔记吧,帮助自己也帮助别人;
  先从Flume源码的编译开始;

下载
  下载源码很简单,去官网或者去github下载,Apache Flume 1.7.0的github源码地址如下:
  https://github.com/apache/flume/tree/release-1.7.0

Maven编译安装
  在mvn install之前,最好先设置下maven的国内镜像地址,加快依赖的下载速度,时间还是很宝贵的,别浪费在无聊的等待上,
  打开maven的setting.xml配置文件,添加如下镜像即可:
  

<mirrors>  
<!-- mirror
  
| Specifies a repository mirror site to use instead of a given repository. The repository that

  
| this mirror serves has an>  
| for inheritance and direct lookup purposes, and must be unique across the set of mirrors.
  
|
  
<mirror>
  
<id>mirrorId</id>
  
<mirrorOf>repositoryId</mirrorOf>
  
<name>Human Readable Name for this Mirror.</name>
  
<url>http://my.repository.com/repo/path</url>
  
</mirror>
  
-->
  

  
<mirror>
  
<id>alimaven</id>
  
<name>aliyun maven</name>
  
<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
  
<mirrorOf>central</mirrorOf>      
  
</mirror>
  

  
</mirrors>
  

  在控制台输入如下命令,后面的参数表示跳过单元测试
  mvn install -Dmaven.test.skip=true
  很快就开始下载依赖了,骚等片刻:

  遗憾的是报错了,坑爹,又是国外的网络不能访问,ping下maven.twttr.com,果真不行,哎,,,

Failed to execute goal on project flume-ng-morphline-solr-sink: Could not resolve dependencies for project org.apache.flume.flume-ng-sinks:flume-ng-morphline-solr-sink:jar:1.7.0: Failed to collect dependencies at org.kitesdk:kite-morphlines-all:pom:1.0.0 -> org.kitesdk:kite-morphlines-useragent:jar:1.0.0 -> ua_parser:ua-parser:jar:1.3.0: Failed to read artifact descriptor for ua_parser:ua-parser:jar:1.3.0: Could not transfer artifact ua_parser:ua-parser:pom:1.3.0 from/to maven-twttr (http://maven.twttr.com): maven.twttr.com: Unknown host maven.twttr.com ->
  网上找了半天解决方案,搞什么代理啊 VPN什么的,有点麻烦,好在找到了一个ip,添加到hosts里即可,如下:
  

199.16.156.89 maven.twttr.com  

  添加完host后,继续执行mvn install -Dmaven.test.skip=true,耐心等待...
  结果等了半天,还是不行,卡在这,又是坑爹的天朝网络,速度真的太慢了,没办法。。。。。conjars.org的访问速度真心太慢...
  Downloading: http://conjars.org/repo/eigenbase/eigenbase-properties/1.1.4/eigenbase-properties-1.1.4.pom
  多试几次吧,反正我是试了好几次,最后终于成功了,也可以尝试在父pom.xml加个repository,如下,实在不行,真的只能代理了,或者把别人已经下好的依赖拷贝到自己的maven本地仓库。
  

<repositories>  
<repository>
  
<id>nexus.axiomalaska.com</id>
  
<url>http://nexus.axiomalaska.com/nexus/content/repositories/public</url>
  
</repository>
  
</repositories>
  



导入Eclipse
  这个没啥好说的,直接导入maven工程即可,遗憾的是flume-ng-core工程还是报错,如下:
  TransferStateFileMeta cannot be resolved to a type
  仔细看看源码,发现确实没有定义TransferStateFileMeta 这个类,这就尴尬了,在检查下,发现pom.xml有错误,需要安装,execution元素那边报错了,鼠标放上去,提示需要安装相应插件,那就安装吧,骚等片刻,终于安装好了,update下maven工程,pom.xml也没报错了。。。
  坑爹的是发现还是报那个错误
  TransferStateFileMeta cannot be resolved to a type
  不过发现问题还是出在pom.xml里的build-helper-maven-plugin这个插件的配置上,好像原因是DurablePositionTracker引用的TransferStateFileMeta这个类是自动生成的,查看target目录,确实找到了这个类,但是为什么还是报错,仔细观察,原来是source没配对,因为TransferStateFileMeta类是在generated-sources的avro目录下的,那就增加个目录呗,在sources节点增加<source>target/generated-sources/avro</source>,如下所示。。
  

            <executions>  
<execution>
  
<id>add-source</id>
  
<phase>generate-sources</phase>
  
<goals>
  
<goal>add-source</goal>
  
</goals>
  
<configuration>
  
<sources>
  
<source>target/generated-sources/java</source>
  <source>target/generated-sources/avro</source>
  
</sources>
  
</configuration>
  
</execution>
  
</executions>
  

  update下工程,终于Ok了,没报任何错误。。。(如果还有错的话,试着先执行mvn eclipse:eclipse命令后再导入)
页: [1]
查看完整版本: Apache Flume 1.7.0 源码编译 导入Eclipse