使用maven在linux上对hadoop 2.2进行编译 0、环境介绍:
Hadoop信息: Version: 2.2 下载地址: 源码包:hadoop-2.2.0-src.tar.gz
软件包:hadoop-2.2.0.tar.gz
Os环境: [iyunv@carefree ~]# lsb_release -a LSB Version::base-4.0-amd64:base-4.0-noarch:core-4.0 Distributor ID:CentOS Description:CentOS release 6.4 (Final) Release:6.4 Codename:Final 解压源码包: 1
| tar -zxvf hadoop-2.2.0-src.tar.gz
|
其中BUILDING.txt文件对于编译做了一个说明,现在就开始着手准备编译工作。 1、前提条件
* 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) * Internet connection for first build (to fetch all Maven and Hadoop dependencies) (ps:需要有网络连接)
2、配置需要的软件环境
前置条件中提到的os要求我们已经满足,需要连接网络添加好即可。 其他的软件包如下: 1
2
3
4
5
6
| apache-maven-3.0.5-bin.tar.gz
cmake-3.0.2.tar.gz
findbugs-2.0.3.tar.gz
hadoop-2.2.0-src.tar.gz
jdk-7u51-linux-x64.tar.gz
protobuf-2.5.0.tar.gz
|
使用tar -zxvf packageName 解压上面的软件包。 对于maven、jdk、findbugs只需要在环境变量中配置好对应的目录即可。 1
2
3
4
5
| vim /etc/profile
export MAVEN_HOME=/u01/app/apache-maven-3.0.5
export JAVA_HOME=/u01/app/jdk1.7.0_51
export FINDBUGS_HOME1=/u01/app/findbugs-2.0.3
export PATH=${FINDBUGS_HOME1}/bin:${JAVA_HOME}/bin:${MAVEN_HOME}/bin:$PATH
|
Cmake的安装可以参考其中的README.txt文件,使用以下命令即可完成安装:./bootstrap && make && make install protobuf的安装参考包中的README.txt文件,使用以下命令即可完成安装:
1
2
3
4
| $ ./configure
$ make
$ make check
$ make install
|
通过以上的步骤我们即可完成前置条件的配置工作。 3、2.2的bug
Hadoop 2.2有一个bug会影响编译,我们这里提前做一个处理,处理方法: 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
| 在hadoop-common-project/hadoop-auth/pom.xml文件中
<dependency>
<groupId>org.mortbay.jetty</groupId>
<artifactId>jetty</artifactId>
<scope>test</scope>
</dependency>
后边添加
<dependency>
<groupId>org.mortbay.jetty</groupId>
<artifactId>jetty-util</artifactId>
<scope>test</scope>
</dependency>
在hadoop-hdfs-project/hadoop-hdfs/pom.xml文件中
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<configuration>
<excludePackageNames>org.apache.hadoop.hdfs.protocol.proto</excludePackageNames>
</configuration>
后边加上
<executions>
<execution>
<id>attach-javadocs</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
|
4、编译
Maven的具体编译命令我们在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 这里我们使用mvn package -Pdist,native,docs,src -DskipTests -Dtar进行编译,在编译的过程中可能由于网络中断,需要重复运行该命令,在这里我们可以进入子包来进行部门编译(相当于分别下载依赖的包),最后再hadoop-2.2.0-src目录下运行该命令。 5、编译完成
编译完成之后,我们进入hadoop-2.2.0-src/hadoop-dist目录下,可以发现一个target目录,在里面我们即可找到编译好的压缩包。 hadoop-2.2.0.tar.gz
|