0x00 ? ?緣由
由于我們從Hadoop的Apache網(wǎng)站上下載的hadoop包是在32位機(jī)器上編譯的温学。因此宙枷,如果我們的機(jī)器的64位的,在使用的時(shí)候就會(huì)出現(xiàn)問(wèn)題蕴忆。所以颤芬,我們要在64位機(jī)器上重新編譯hadoop。
0x01 ? ?準(zhǔn)備
OS: CentOS6 64位 ? ? ? ?Hadoop版本:2.6.0
Hadoop2.6.0源碼下載地址:
http://archive.apache.org/dist/hadoop/common/hadoop-2.6.0/hadoop-2.6.0-src.tar.gz
0x02 ? ?編譯前的準(zhǔn)備工作
參考BUILDING.txt
hadoop2.6.0目錄下套鹅,有一個(gè)BUILDING.txt文件站蝠,這是編譯的說(shuō)明。
Build instructions for Hadoop
------------------------------------------------------------------
Requirements:
* Unix System
* JDK 1.6+
* Maven 3.0 or later
* Findbugs 1.3.9 (if running findbugs)
* ProtocolBuffer 2.5.0
* CMake 2.6 or newer (if compiling native code)
* Zlib devel (if compiling native code)
* openssl devel ( if compiling native hadoop-pipes )
* Internet connection for first build (to fetch all Maven and Hadoop dependencies)
------------------------------------------------------------------
把JDK卓鹿、Maven沉衣、ProtocolBuffer2.5.0、Cmake减牺、zlib豌习、openssl-devel先安裝好
0x03 ? ?編譯
依然參考BUILDING.txt
------------------------------------------------------------------
Building distributions:
Create binary distribution without native code and without documentation:
$ mvn package -Pdist -DskipTests -Dtar
Create binary distribution with native code and with documentation:
$ mvn package -Pdist,native,docs -DskipTests -Dtar
Create source distribution:
$ mvn package -Psrc -DskipTests
Create source and binary distributions with native code and documentation:
$ mvn package -Pdist,native,docs,src -DskipTests -Dtar
Create a local staging version of the website (in /tmp/hadoop-site)
$ mvn clean site; mvn site:stage -DstagingDirectory=/tmp/hadoop-site
------------------------------------------------------------------
進(jìn)入Hadoop2.6.0目錄下:
這里我們使用:?mvn package -Pdist,native,docs,src -DskipTests -Dtar來(lái)編譯
注:為了防止在編譯的時(shí)候出現(xiàn)內(nèi)存溢出的錯(cuò)誤,我們需要手動(dòng)指定一下maven使用內(nèi)存的大小
Handling out of memory errors in builds
------------------------------------------------------------------
If the build process fails with an out of memory error, you should be able to fix
it by increasing the memory used by maven -which can be done via the environment
variable MAVEN_OPTS.
Here is an example setting to allocate between 256 and 512 MB of heap space to
Maven
export MAVEN_OPTS="-Xms256m -Xmx512m"
------------------------------------------------------------------
編譯順利的話拔疚,一個(gè)小時(shí)左右肥隆,就能完成編譯。
編譯好生成的hadoop文件在這個(gè)目錄下:hadoop-2.6.0-src/hadoop-dist/target/
有一個(gè)文件:hadoop-2.6.0.tar.gz
就是我們編譯好的hadoop2.6.0
0x04 ? ?編譯時(shí)遇到的幾個(gè)錯(cuò)誤
-錯(cuò)誤1:
Failed to execute goal org.apache.maven.plugins:maven-javadoc-plugin:2.8.1:jar (module-javadocs) on project hadoop-annotations: MavenReportException: Error while creating archive:
[ERROR] Exit code: 1 - /opt/hadoop-2.6.0-src/hadoop-common-project/hadoop-annotations/src/main/java/org/apache/hadoop/classification/InterfaceStability.java:27: error: unexpected end tag:
解決辦法:在編譯命令后面加個(gè)Dmaven.javadoc.skip=true的參數(shù)即可
mvn clean package -Pdist,native,docs,src -DskipTests -Dtar -Dmaven.javadoc.skip=true
-錯(cuò)誤2:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-antrun-plugin:1.7:run (site) on project hadoop-common: An Ant BuildException has occured: input file /opt/hadoop-2.6.0-src/hadoop-common-project/hadoop-common/target/findbugsXml.xml does not exist
[ERROR] around Ant part ...... @ 44:234 in /opt/hadoop-2.6.0-src/hadoop-common-project/hadoop-common/target/antrun/build-main.xml
解決辦法:去掉編譯命令中的docs參數(shù)
mvn clean package -Pdist,native,src -DskipTests -Dtar -Dmaven.javadoc.skip=true
解決了這兩個(gè)報(bào)錯(cuò)稚失,編譯應(yīng)該就沒(méi)有什么問(wèn)題了栋艳。
我自己編譯的時(shí)候遇到了這兩個(gè)報(bào)錯(cuò),編譯hadoop2.5.2的方法同上句各!
可以看到吸占,編譯完成用了20多分鐘。不同的機(jī)器配置凿宾,可能耗費(fèi)的時(shí)間會(huì)有所不同矾屯。
不足之處,請(qǐng)批評(píng)指正初厚。
如有問(wèn)題件蚕,請(qǐng)私信聯(lián)系。
謝謝!