1、准备阶段
使用root登录Centos,并且要求能够正常连接网络。配置清单如下:
(1)hadoop-2.7.2-src.tar.gz
(2)jdk-8u144-linux-x64.tar.gz
(3)apache-ant-1.9.9-bin.tar.gz(build工具,打包用的)
(4)apache-maven-3.0.5-bin.tar.gz
(5)protobuf-2.5.0.tar.gz(序列化的框架)
1.1、下载Hadoop源码包
https://hadoop.apache.org/releases.html
1.2、安装、配置maven
tar -zxvf apache-maven-3.0.5-bin.tar.gz -C /opt/module/
配置maven镜像源
vi conf/settings.xml
添加以下内容
<mirror> <id>nexus-aliyun</id> <mirrorOf>central</mirrorOf> <name>Nexus aliyun</name> <url>http://maven.aliyun.com/nexus/content/groups/public</url> </mirror>
配置maven环境变量
vi /etc/profile
添加一下内容
![](/qrcode.jpg)
#MAVEN_HOME export MAVEN_HOME=/opt/module/apache-maven-3.0.5 export PATH=$PATH:$MAVEN_HOME/bi
使得配置信息生效
source /etc/profile
验证maven是否安装成功:
[root@hadoop-102 software]# mvn -version Apache Maven 3.0.5 (r01de14724cdef164cd33c7c8c2fe155faf9602da; 2013-02-19 08:51:28-0500) Maven home: /opt/module/apache-maven-3.0.5 Java version: 1.8.0_144, vendor: Oracle Corporation Java home: /opt/module/jdk1.8.0_144/jre Default locale: en_US, platform encoding: UTF-8 OS name: "linux", version: "3.10.0-957.el7.x86_64", arch: "amd64", family: "unix" You have new mail in /var/spool/mail/root [root@hadoop-102 software]#
1.3 、安装、配置Ant
[root@hadoop-102 software]# tar -zxvf apache-ant-1.9.9-bin.tar.gz -C /opt/module/
[root@hadoop-102 software]# vi /etc/profile
#ANT_HOME
export ANT_HOME=/opt/module/apache-ant-1.9.9
export PATH=$PATH:$ANT_HOME/bin
[root@hadoop-102 software]# source /etc/profile
[root@hadoop-102 software]#
[root@hadoop-102 software]# ant -version
Apache Ant(TM) version 1.9.9 compiled on February 2 2017
[root@hadoop-102 software]#
1.4、安装glibc-headers 和 gcc-c++
[root@hadoop-102 software]# yum -y install glibc-headers
[root@hadoop-102 software]# yum install gcc-c++
1.5、安装make和cmake
[root@hadoop-102 software]# yum install make [root@hadoop-102 software]# yum install cmake
1.6、编译安装protobuf
[root@hadoop-102 software]# tar -zxvf protobuf-2.5.0.tar.gz -C /opt/module/ [root@hadoop-102 software]# cd /opt/module/protobuf-2.5.0/ [root@hadoop-102 protobuf-2.5.0]# [root@hadoop-102 protobuf-2.5.0]#./configure [root@hadoop-102 protobuf-2.5.0]# make [root@hadoop-102 protobuf-2.5.0]# make check [root@hadoop-102 protobuf-2.5.0]# make install [root@hadoop-102 protobuf-2.5.0]# ldconfig
配置环境变量:
[root@hadoop-102 protobuf-2.5.0]# vi /etc/profile #LD_LIBRARY_PATH export LD_LIBRARY_PATH=/opt/module/protobuf-2.5.0 export PATH=$PATH:$LD_LIBRARY_PATH [root@hadoop-102 protobuf-2.5.0]# source /etc/profile [root@hadoop-102 protobuf-2.5.0]# protoc --version libprotoc 2.5.0
1.7、安装openssl和 ncurses-devel库
[root@hadoop-102 ~]# yum -y install openssl-devel [root@hadoop-102 ~]# yum -y install ncurses-devel
jdk的安装时,解压后配置环境变量,这里就不在赘述。
2、编译Hadoop
2.1、解压源码包
[root@hadoop-102 hadoop-2.7.2-src]# tar -zxvf hadoop-2.7.2-src.tar.gz -C /opt/ [root@hadoop-102 software]# cd /opt/hadoop-2.7.2-src/ [root@hadoop-102 hadoop-2.7.2-src]#
2.2、编译
切入到解压后的目录中,执行:
mvn package -Pdist,native -DskipTests -Dtar
2.3、查看编译结果
编译完成后,hadoop包在/opt/hadoop-2.7.2-src/hadoop-dist/target目录下。
3、编译源码过程中常见的问题及解决方案
(1)MAVEN install时候JVM内存溢出
处理方式:在环境配置文件和maven的执行文件均可调整MAVEN_OPT的heap大小。
(详情查阅MAVEN 编译 JVM调优问题,如:http://outofmemory.cn/code-snippet/12652/maven-outofmemoryerror-method)
(2)编译期间maven报错。可能网络阻塞问题导致依赖库下载不完整导致,多次执行命令(一次通过比较难):
mvn package -Pdist,nativeN -DskipTests -Dtar
(3)报ant、protobuf等错误,插件下载未完整或者插件版本问题,最开始链接有较多特殊情况,同时推荐
2.7.0版本的问题汇总帖子 http://www.tuicool.com/articles/IBn63qf