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 ID that matches the mirrorOf element of this mirror. IDs are used
     | 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,果真不行,哎,,,

 [ERROR] 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 -> [Help 1]

 網上找了半天解決方案,搞什么代理啊 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命令后再導入)

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM