百般波折的Hadoop编译

终于不能忍了,每次使用hadoop都出native库警告,于是决定编译hadoop,也是走了不少弯路。唯一参考了官方文档,当初居然没想到去百度一篇别人编译的过程,先填坑,哎~ 说多了都是泪。

准备

首先从官方下载hadoop2.6.4的源码包(Hadoop分布式集群安装一文有介绍),同时查看了官方文档对于Native Bulid的需求描述:

  • C compiler (e.g. GNU C Compiler)
  • GNU Autools Chain: autoconf, automake, libtool
  • zlib-development package (stable version >= 1.2.0)
  • openssl-development package(e.g. libssl-dev)
  • 先查询系统是否有这些环境库:
1
rpm -qa | grep -E "gcc|autoconf|automake|libtool|libssl-dev"

zlib是有的,版本1.2.3,达到要求,下面开始安装没有的gcccmakeautoconfautomake,以及libssl-dev

1
yum install openssl-devel gcc cmake autoconf automake

libssl-dev

由于libssl-devyum安装时叫openssl-devel,pkgs上的rpm包版本是1.0.2i,但使用命令openssl version查看系统当前openssl的版本是1.0.1e,与要安装的libssl-dev包不符,需要升级openssl,下载openssl源码包编译

1
wget https://www.openssl.org/source/openssl-1.0.2i.tar.gz

解压,进入目录运行config可执行文件,报错

1
c_zlib.c:25:19: error: zlib.h: No such file or directory

zlib.h不存在,那就是缺少zlib-dev的包,yum install zlib-dev,没有这个包?yum search zlib,原来叫zlib-devel,安装完成后重新运行config,通过,然后makemake install

完成后查看版本,openssl version,版本居然还是1.0.1e,哪里不对,翻上去看看make install时的输出,有下面一段:

1
2
3
4
5
6
7
8
9
created directory `/usr/local/ssl/bin’
created directory `/usr/local/ssl/lib’
created directory `/usr/local/ssl/lib/engines’
created directory `/usr/local/ssl/lib/pkgconfig’
created directory `/usr/local/ssl/include’
created directory `/usr/local/ssl/include/openssl’
created directory `/usr/local/ssl/misc’
created directory `/usr/local/ssl/certs’
created directory `/usr/local/ssl/private’

哦,原来是安装在/usr/local/ssl目录下了,运行/usr/local/ssl/bin/openssl version,版本是1.0.2i,那好办

1
2
3
4
5
mv /usr/bin/openssl /usr/bin/openssl.old
ln -s /usr/local/ssl/bin/openssl /usr/bin/openssl
ln -s /usr/local/ssl/include/openssl /usr/include/openssl
echo '/usr/local/ssl/lib'>> /etc/ld.so.conf
ldconfig -v

上述命令依次备份了旧版本的openssl,但由于/usr/include下没有openssl的头文件库,就不去管它,接着在/usr/bin下创建名为openssl的软连接到/usr/local/ssl/bin/openssl以代替原来的旧版本,
同理,头文件库也是。最后别忘了动态共享库,把openssl新的lib路径加到Id.so.conf中,执行Idconfig命令生成缓存,现在再openssl version一下,版本变1.0.2i了。

编译

按照官方文档说的,输入以下命令执行编译:

1
mvn package -Pdist,native -DskipTests -Dtar

一看mvn命令,maven环境的安装也就不多说了。

再次运行编译。

1
[ERROR] Failed to execute goal org.apache.hadoop:hadoop-maven-plugins:2.6.4:protoc (compile-protoc) on project hadoop-common: org.apache.maven.plugin.MojoExecutionException: ‘protoc –version’ did not return a version -> [Help 1]

没有protocol Buffer compiler,下载一个,在官方github上,我选择了2.6.1版本的https://github.com/google/protobuf/tree/v2.6.1

下载解压后运行./autogen.sh

1
2
3
4
5
6
7
8
9
10
11
12
Google Test not present.  Fetching gtest-1.5.0 from the web…
curl: (7) Failed to connect to 2404:6800:4008:c01::52: Network is unreachable
bzip2: Compressed file ends unexpectedly;
perhaps it is corrupted? *Possible* reason follows.
bzip2: Invalid argument
Input file = (stdin), output file = (stdout)
It is possible that the compressed file(s) have become corrupted.
You can use the -tvv option to test integrity of such files.
You can use the `bzip2recover’ program to attempt to recover
data from undamaged sections of corrupted files.
tar: Child returned status 2
tar: Error is not recoverable: exiting now

打开脚本文件看看是怎么回事。

1
2
3
4
5
if test ! -e gtest; then
echo "Google Test not present. Fetching gtest-1.5.0 from the web..."
curl http://googletest.googlecode.com/files/gtest-1.5.0.tar.bz2 | tar jx
mv gtest-1.5.0 gtest
fi

浏览器打开这个链接果然是404(挂了代理的),看样子是要下载一个gtest-1.5.0的tar包,上github找找,原来是google test,https://github.com/google/googletest/tree/release-1.5.0

下载这个版本的tar包,解压后将文件夹重命名为gtest(注意是在当前protobuf的目录下),进入make目录输入make编译。

1
2
3
g++ -I../include -g -Wall -Wextra -c ../samples/sample1.cc
make: g++: Command not found
make: *** [sample1.o] Error 127

好吧,缺c++的编译环境,yum install gcc-c++ ,再次运行编译,成功。返回protobuf的目录,重新运行autogen.sh

1
+ exit 0

看到结束状态为0,成功。在目录下多了一个configure可执行文件,运行它。

1
2
3
4
5
config.status: creating Makefile
config.status: creating scripts/gtest-config
config.status: creating build-aux/config.h
config.status: executing depfiles commands
config.status: executing libtool commands

最后这几行输出很重要,如果没有可能是前面某环节出错了,此时就可以make了,编译开始,输入make,经过几分钟等待,编译完成。make check下,看到一大堆的OKPASSED就说明没问题了,
现在安装它,make install,完成,返回hadoop的编译,重新执行命令mvn package -Pdist,native -DskipTests -Dtar

1
[ERROR] Failed to execute goal org.apache.hadoop:hadoop-maven-plugins:2.6.4:protoc (compile-protoc) on project hadoop-common: org.apache.maven.plugin.MojoExecutionException: protoc version is ‘libprotoc 2.6.1’, expected version is ‘2.5.0’ -> [Help 1]

WTF?你官方文档也没说啊!

先去protobuf目录make uninstall,再去下载2.5.0版本的https://github.com/google/protobuf/archive/v2.5.0.zip

好在2.6.1编译时的坑都填了,解压后把原来2.6.1版本的目录下的gtest文件夹拷到2.5.0版本的目录下,依旧是按步骤执行autogen.shconfiguremakemake checkmake install

一切OK,没有任何问题,还是确认一下版本,输入命令protoc --version

1
libprotoc 2.5.0

没问题,再次回到hadoop编译,运行mvn package的命令。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
[ERROR] /home/bigdata/hadoop-2.6.4-src/hadoop-common-project/hadoop-nfs/src/main/java/org/apache/hadoop/nfs/nfs3/Nfs3Interface.java:42: warning: no @return
[ERROR] public NFS3Response access(XDR xdr, RpcInfo info);
[ERROR] ^
[ERROR] /home/bigdata/hadoop-2.6.4-src/hadoop-common-project/hadoop-nfs/src/main/java/org/apache/hadoop/nfs/nfs3/Nfs3Interface.java:45: warning: no @param for xdr
[ERROR] public NFS3Response readlink(XDR xdr, RpcInfo info);
[ERROR] ^
[ERROR]
[ERROR] Command line was: /usr/local/jdk1.8.0_101/jre/../bin/javadoc @options @packages
[ERROR]
[ERROR] Refer to the generated Javadoc files in ‘/home/bigdata/hadoop-2.6.4-src/hadoop-common-project/hadoop-nfs/target’ dir.
[ERROR] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
[ERROR]
[ERROR] After correcting the problems, you can resume the build with the command
[ERROR] mvn <goals> -rf :hadoop-nfs

javadoc生成出错?不要了,跳过它,加-Dmaven.javadoc.skip=true 跳过javadoc生成,重新运行编译。

1
2
3
4
5
6
7
[INFO] ————————————————————————
[INFO] BUILD SUCCESS
[INFO] ————————————————————————
[INFO] Total time: 03:24 h
[INFO] Finished at: 2016-09-25T14:55:23+08:00
[INFO] Final Memory: 94M/206M
[INFO] ————————————————————————

看到这段,激动不已,终于成功了,到hadoop-dist/target/hadoop-2.6.4/lib/native目录下拷走native库到hadoop的native库目录下,然后终于没有警告了,感觉世界清静了呢~


百般波折的Hadoop编译
https://vicasong.github.io/big-data/hadoop-make-install/
作者
Vica
发布于
2016年9月26日
许可协议