logo头像
Snippet 博客主题

Hadoop学习之路(三)Hadoop-2.7.5在CentOS-6.7上的编译

** Hadoop学习之路(三)Hadoop-2.7.5在CentOS-6.7上的编译:** <Excerpt in index | 首页摘要>

​ Hadoop学习之路(三)Hadoop-2.7.5在CentOS-6.7上的编译

<The rest of contents | 余下全文>

下载Hadoop源码

1、登录官网

img

img

2、确定你要安装的软件的版本

一个选取原则: 不新不旧的稳定版本

几个标准:

  1)一般来说,刚刚发布的大版本都是有很多问题

  2)应该选择某个大版本中的最后一个小版本

阅读编译文档

1、准备一个hadoop源码包,我选择的hadoop的版本是:hadoop-2.7.5-src.tar.gz,在hadoop-2.7.5-src.tar.gz的源码包根目录下有一个文档叫做BUINDING.txt,这其中说明了编译hadoop所需要的一些编译环境相关的东西。不同的hadoop版本的要求都不一样。对应的版本参照BUINDING.txt。

1
2
3
4
5
6
7
8
9
10
11
12
Requirements:

* Unix System
* JDK 1.7+
* 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 and to get the best HDFS encryption performance )
* Linux FUSE (Filesystem in Userspace) version 2.6 or above ( if compiling fuse_dfs )
* Internet connection for first build (to fetch all Maven and Hadoop dependencies)

软件安装

对应以上需求,我们准备好所要求版本的这些软件。

JDK的安装

选择版本:jdk1.8.0_73

安装依赖包

根据编译指导文件BUILDING.txt,安装相关依赖程序包

1
[root@master soft]# yum -y install gcc-c++ build-essential autoconf automake libtool cmake zlib1g-dev pkg-config libssl-devua svn openssl-devel ncurses-devel

img

安装Maven

编译要求:Maven 3.0 or later
安装软件:apache-maven-3.0.5-bin.tar.gz

1
`[root@hadoop1 soft]# ls``apache-maven-3.3.9-bin.tar.gz``[root@hadoop1 soft]# chmod 755 apache-maven-3.3.9-bin.tar.gz``[root@hadoop1 soft]# tar -zxvf apache-maven-3.3.9-bin.tar.gz <br>。。。<br>[root@hadoop1 soft]# mv apache-maven-3.3.9 /opt/<br>[root@hadoop1 soft]# vi /etc/profile`

img

img

配置mvn的环境变量

export M2_HOME=/opt/apache-maven-3.3.
export PATH=$PATH:$M2_HOME/bin

测试

1
2
3
4
5
6
7
8
[root@hadoop1 soft]# mvn -v
Apache Maven 3.3.9 (bb52d8502b132ec0a5a3f4c09453c07478323dc5; 2015-11-11T00:41:47+08:00)
Maven home: /opt/apache-maven-3.3.9
Java version: 1.8.0_73, vendor: Oracle Corporation
Java home: /usr/local/jdk1.8.0_73/jre
Default locale: zh_CN, platform encoding: UTF-8
OS name: "linux", version: "2.6.32-573.el6.x86_64", arch: "amd64", family: "unix"
[root@hadoop1 soft]#

img

安装Findbugs

编译要求:Findbugs 1.3.9
安装软件:findbugs-3.0.1.tar.gz

1
2
3
4
[root@hadoop1 soft]# ls
findbugs-3.0.1.tar.gz
[root@hadoop1 soft]# chmod 755 findbugs-3.0.1.tar.gz
[root@hadoop1 soft]# tar -zxvf findbugs-3.0.1.tar.gz -C /opt

配置Findbugs环境变量

1
[root@hadoop1 soft]# vi /etc/profile

export FINDBUGS_HOME=/opt/findbugs-3.0.1
export PATH=$PATH:$FINDBUGS_HOME/bin

img

测试

1
2
3
[root@hadoop1 soft]# findbugs -version
3.0.1
[root@hadoop1 soft]#

img

安装ProtocolBuffer

编译要求:ProtocolBuffer 2.5.0
安装软件:protobuf-2.5.0.tar.gz,不建议用其它版本

1
2
3
4
[root@hadoop1 soft]# ls
protobuf-2.5.0.tar.gz
[root@hadoop1 soft]# chmod 755 protobuf-2.5.0.tar.gz
[root@hadoop1 soft]# tar -zxvf protobuf-2.5.0.tar.gz -C /opt[root@hadoop1 soft]# cd /opt/protobuf-2.5.0/[root@hadoop1 protobuf-2.5.0]# ./configure [root@hadoop1 protobuf-2.5.0]# make[root@hadoop1 protobuf-2.5.0]# make install

测试

1
2
3
[root@hadoop1 protobuf-2.5.0]# protoc --version
libprotoc 2.5.0
[root@hadoop1 protobuf-2.5.0]#

img

修改maven的配置文件,添加maven的下载源

[root@hadoop1 protobuf-2.5.0]# cd /opt/apache-maven-3.3.9/conf/
[root@hadoop1 conf]# vi settings.xml

在mirrors中添加alimaven的下载源

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
<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>alimaven</id>
<mirrorOf>central</mirrorOf>
<name>aliyun maven</name>
<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
</mirror>
<mirror>
<id>mirrorId</id>
<mirrorOf>repositoryId</mirrorOf>
<name>Human Readable Name for this Mirror.</name>
<url>http://my.repository.com/repo/path</url>
</mirror>
-->
</mirrors>

安装Ant

1
2
3
[root@hadoop1 soft]# ls
apache-ant-1.9.4-bin.tar.gz hadoop-2.7.5-src
[root@hadoop1 soft]# tar -zxvf apache-ant-1.9.4-bin.tar.gz -C /opt/

配置环境变量

1
2
3
4
[root@hadoop1 apache-ant-1.9.4]# vi /etc/profile
#Ant
export ANT_HOME=/opt/apache-ant-1.9.4
export PATH=$PATH:$ANT_HOME/bin

检测

1
2
3
[root@hadoop1 apache-ant-1.9.4]# ant -version
Apache Ant(TM) version 1.9.4 compiled on April 29 2014
[root@hadoop1 apache-ant-1.9.4]#

img

安装Snappy

解压

1
2
3
[root@hadoop1 soft]# ls
hadoop-2.7.5-src snappy-1.1.1.tar.gz
[root@hadoop1 soft]# tar -zxvf snappy-1.1.1.tar.gz -C /opt/

安装

1
2
3
4
[root@hadoop1 soft]# cd /opt/snappy-1.1.1/
[root@hadoop1 snappy-1.1.1]# ./configure
[root@hadoop1 snappy-1.1.1]# make
[root@hadoop1 snappy-1.1.1]# make install

查看snappy文件库

1
2
3
4
5
6
7
[root@hadoop1 snappy-1.1.1]# ls -lh /usr/local/lib | grep snappy
-rw-r--r-- 1 root root 228K 3月 3 09:51 libsnappy.a
-rwxr-xr-x 1 root root 953 3月 3 09:51 libsnappy.la
lrwxrwxrwx 1 root root 18 3月 3 09:51 libsnappy.so -> libsnappy.so.1.2.0
lrwxrwxrwx 1 root root 18 3月 3 09:51 libsnappy.so.1 -> libsnappy.so.1.2.0
-rwxr-xr-x 1 root root 145K 3月 3 09:51 libsnappy.so.1.2.0
[root@hadoop1 snappy-1.1.1]#

开始编译hadoop

1
2
[root@hadoop1 soft]# ls
[root@hadoop1 soft]# tar -zxvf hadoop-2.7.5-src.tar.gz

在编译之前防止java.lang.OutOfMemoryError:Java heap space堆栈问题,在centos系统中执行命令

1
[root@hadoop1 snappy-1.1.1]# export MAVEN_OPTS="-Xms256m -Xmx512m"

进入源码包下,执行命令进行编译

1
2
[root@hadoop1 snappy-1.1.1]# cd /soft/hadoop-2.7.5-src/
[root@hadoop1 hadoop-2.7.5-src]# mvn package -Pdist,native,docs -DskipTests -Dtar

如果中途编译失败,并且不要文档的话,请使用这个命令:

1
[root@master ~]# mvn clear package -Pdist,native -DskipTests -Dtar -Dsnappy.lib=/usr/local/lib -Dbundle.snappy -Drequire.openssl

img

编译成功之后,hadoop-2.7.5.tar.gz位于/soft/hadoop-2.7.5-src/hadoop-dist/target目录下,这是编译后文件夹的状态

img

至此,大功告成!!!