由于需要对hadoop进行二次开发,所以需要使用源码编译版本的hadoop,记录hadoop编译过程如下:
基本工具
安装brew
brew官网,点击进入官网,直接安装即可。安装成功后可以输入brew -v
查看是否安装成功,成功则显示:
下载hadoop2.6源码
hadoop-release页面,需要注意的地方是:文件名中有src的表示是源码,需要编译才能运行。不带src的是已经编译好的二进制安装包。
另外,在下载下来的源码文件夹中,有building.txt,其实已经写明了各个系统编译的步骤,其中unix系列的系统要求为:
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), must be 3.0 or newer on Mac
- 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)
编译环境
jdk1.6及以上
jdk12.0.1下载,装好后在命令行java -version
查看是否安装成功,成功则显示:
Maven3.0及以上
去maven官网安装,装好后命令行mvn -version
查看是否成功,成功则显示:
findbugs
主要是用于寻找静态bug,笔者因为二次开发添加的地方很小,这块先不安装了,后期需要再安装
ProtocolBuffer2.5.0
安装参考成功后在命令行protoc --version
,成功则显示:libprotoc 2.5.0
CMake 3.0+
利用brew工具安装cmake,首先命令行执行:ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
等待直到出现:==> Installation successful!,然后再在命令行执行brew install cmake
,成功的话会显示:
然后在/etc/profile文件中添加下面两句:
export LDFLAGS="-L/usr/local/opt/zlib/lib"
export CPPFLAGS="-I/usr/local/opt/zlib/include"
Zlib devel
命令行执行brew install zlib
openssl devel
命令行执行brew install openssl
,成功后执行openssl version
可显示:
编译
依旧是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
笔者有自己写的代码,显然按照第2种方式编译。对后面几种options的解释如下:
-Pdist:给编译后的二进制安装包生成说明文档
-DskipTests:编译时跳过test
-Dtar:编译后的二进制安装包为压缩包
编译源码,在命令行先执行mvn clean
删掉之前可能的残留,然后再mvn package -Pdist,native -DskipTests -Dtar
,最后显示BUILD SUCCESS即成功。
注:因为hadoop2.6.0版本较老,用1.7及以上的jdk,在编译的时候会出现语法报错:[ERROR] 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:
对此的解决措施为:在编译过程中,不要生成javadoc文件即可,即编译的语句改为:mvn clean package -Pdist,native -DskipTests -Dtar -Dmaven.javadoc.skip=true
修改后编译成功如下,编译成功后的包位于$HADOOP_HOME/hadoop-dist/target下