Hadoop编译源码(面试重点)

版本:Apache Hadoop 2.7.2

下载地址:https://www.apache.org/dyn/closer.cgi/hadoop/common/hadoop-2.7.2/hadoop-2.7.2-src.tar.gz

查看识别Hadoop是32位还是64位:https://www.linuxidc.com/Linux/2017-03/142049.htm 

 

解压后 在第一级目录中找到 BUILDING.txt 文件,就可以看到编译所需的库或者工具

----------------------------------------------------------------------------------
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 )
* Jansson C XML parsing library ( if compiling libwebhdfs )
* 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)

----------------------------------------------------------------------------------

除了上面这些,为了不出错,实际还需要autoconf automake gcc等

 

1、前期准备工作
1.1、CentOS联网
配置CentOS能连接外网。Linux虚拟机ping www.baidu.com 是畅通的

注意:采用root角色编译,减少文件夹权限出现问题

1.2、jar包准备(hadoop源码、JDK8、maven、ant 、protobuf)
(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(序列化的框架)

注: 在 /opt 目录下创建两个文件夹,一个 software 存放安装包,一个 module 存放安装的软件。

2、jar包安装
注意:所有操作必须在root用户下完成

2.1、JDK解压、配置环境变量 JAVA_HOME和PATH,验证java-version(如下都需要验证是否配置成功)
[root@hadoop101 software] # tar -zxf jdk-8u144-linux-x64.tar.gz -C /opt/module/
[root@hadoop101 software]# vi /etc/profile
#JAVA_HOME:
export JAVA_HOME=/opt/module/jdk1.8.0_144
export PATH=$PATH:$JAVA_HOME/bin
[root@hadoop101 software]# source /etc/profile
验证命令:java -version


2.2、 Maven解压、配置  MAVEN_HOME和PATH
[root@hadoop101 software]# tar -zxvf apache-maven-3.0.5-bin.tar.gz -C /opt/module/

/opt/module/apache-maven-3.0.5

[root@hadoop101 apache-maven-3.0.5]# vi conf/settings.xml

<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>mirrorId</id>
       <mirrorOf>repositoryId</mirrorOf>
       <name>Human Readable Name for this Mirror.</name>
       <url>http://my.repository.com/repo/path</url>
      </mirror>
     -->
        <mirror>
                <id>nexus-aliyun</id>
                <mirrorOf>central</mirrorOf>
                <name>Nexus aliyun</name>
                <url>http://maven.aliyun.com/nexus/content/groups/public</url>
        </mirror>
</mirrors>

//红色的就是替换成阿里云的服务器,加快下载速度,用默认的也可以。

 

注: settings.xml 时为了加快访问网络访问速度,可以不配置。 

[root@hadoop101 apache-maven-3.0.5]# vi /etc/profile
#MAVEN_HOME
export MAVEN_HOME=/opt/module/apache-maven-3.0.5
export PATH=$PATH:$MAVEN_HOME/bin
[root@hadoop101 software]# source /etc/profile
验证命令:mvn -version

2.3、 ant解压、配置  ANT _HOME和PATH
[root@hadoop101 software]# tar -zxvf apache-ant-1.9.9-bin.tar.gz -C /opt/module/ 
[root@hadoop101 apache-ant-1.9.9]# vi /etc/profile
#ANT_HOME
export ANT_HOME=/opt/module/apache-ant-1.9.9
export PATH=$PATH:$ANT_HOME/bin
[root@hadoop101 software]#source /etc/profile
验证命令:ant -version

2.4、 安装  glibc-headers 和  g++  
命令如下:
[root@hadoop101 apache-ant-1.9.9]# yum install glibc-headers -y
[root@hadoop101 apache-ant-1.9.9]# yum install gcc-c++ -y


2.5、安装make和cmake
[root@hadoop101 apache-ant-1.9.9]# yum install make -y
[root@hadoop101 apache-ant-1.9.9]# yum install cmake -y

2.6、 解压protobuf
进入到解压后protobuf主目录,/opt/module/protobuf-2.5.0,然后相继执行命令

[root@hadoop101 software]# tar -zxvf protobuf-2.5.0.tar.gz -C /opt/module/
[root@hadoop101 opt]# cd /opt/module/protobuf-2.5.0/
[root@hadoop101 protobuf-2.5.0]#./configure 
[root@hadoop101 protobuf-2.5.0]# make 
[root@hadoop101 protobuf-2.5.0]# make check 
[root@hadoop101 protobuf-2.5.0]# make install 
[root@hadoop101 protobuf-2.5.0]# ldconfig 
[root@hadoop101 hadoop-dist]# vi /etc/profile
#LD_LIBRARY_PATH
export LD_LIBRARY_PATH=/opt/module/protobuf-2.5.0
export PATH=$PATH:$LD_LIBRARY_PATH
[root@hadoop101 software]#source /etc/profile
验证命令:protoc --version

2.7、 安装openssl库
[root@hadoop101 software]#yum install openssl-devel -y

2.8、 安装 ncurses-devel库
[root@hadoop101 software]#yum install ncurses-devel -y

到此,编译工具安装基本完成。
 

3、编译源码
3.1、 解压源码到/opt/目录
[root@hadoop101 software]# tar -zxvf hadoop-2.7.2-src.tar.gz  -C  /opt/

3.2、 进入到hadoop源码主目录
[root@hadoop101 hadoop-2.7.2-src]# pwd

/opt/hadoop-2.7.2-src

3.3、通过maven执行编译命令
[root@hadoop101 hadoop-2.7.2-src]#mvn package -Pdist,native -DskipTests  -Dtar

等等等等待时间30分钟左右,最终成功是全部SUCCESS。

 [INFO] Executed tasks
[INFO] 
[INFO] --- maven-javadoc-plugin:2.8.1:jar (module-javadocs) @ hadoop-dist ---
[INFO] Building jar: /opt/hadoop-2.7.2-src/hadoop-dist/target/hadoop-dist-2.7.2-javadoc.jar
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO] 
[INFO] Apache Hadoop Main ................................ SUCCESS [1.309s]
[INFO] Apache Hadoop Project POM ......................... SUCCESS [1.015s]
[INFO] Apache Hadoop Annotations ......................... SUCCESS [2.806s]
[INFO] Apache Hadoop Assemblies .......................... SUCCESS [0.235s]
[INFO] Apache Hadoop Project Dist POM .................... SUCCESS [1.828s]
[INFO] Apache Hadoop Maven Plugins ....................... SUCCESS [2.785s]
[INFO] Apache Hadoop MiniKDC ............................. SUCCESS [2.337s]
[INFO] Apache Hadoop Auth ................................ SUCCESS [3.363s]
[INFO] Apache Hadoop Auth Examples ....................... SUCCESS [2.837s]
[INFO] Apache Hadoop Common .............................. SUCCESS [1:25.982s]
[INFO] Apache Hadoop NFS ................................. SUCCESS [7.002s]
[INFO] Apache Hadoop KMS ................................. SUCCESS [31.823s]
[INFO] Apache Hadoop Common Project ...................... SUCCESS [0.156s]
[INFO] Apache Hadoop HDFS ................................ SUCCESS [3:31.354s]
[INFO] Apache Hadoop HttpFS .............................. SUCCESS [24.780s]
[INFO] Apache Hadoop HDFS BookKeeper Journal ............. SUCCESS [45.290s]
[INFO] Apache Hadoop HDFS-NFS ............................ SUCCESS [4.000s]
[INFO] Apache Hadoop HDFS Project ........................ SUCCESS [0.060s]
[INFO] hadoop-yarn ....................................... SUCCESS [0.045s]
[INFO] hadoop-yarn-api ................................... SUCCESS [29.214s]
[INFO] hadoop-yarn-common ................................ SUCCESS [3:43.310s]
[INFO] hadoop-yarn-server ................................ SUCCESS [0.049s]
[INFO] hadoop-yarn-server-common ......................... SUCCESS [8.947s]
[INFO] hadoop-yarn-server-nodemanager .................... SUCCESS [10.178s]
[INFO] hadoop-yarn-server-web-proxy ...................... SUCCESS [2.629s]
[INFO] hadoop-yarn-server-applicationhistoryservice ...... SUCCESS [5.185s]
[INFO] hadoop-yarn-server-resourcemanager ................ SUCCESS [15.641s]
[INFO] hadoop-yarn-server-tests .......................... SUCCESS [3.943s]
[INFO] hadoop-yarn-client ................................ SUCCESS [5.242s]
[INFO] hadoop-yarn-server-sharedcachemanager ............. SUCCESS [3.398s]
[INFO] hadoop-yarn-applications .......................... SUCCESS [0.053s]
[INFO] hadoop-yarn-applications-distributedshell ......... SUCCESS [3.113s]
[INFO] hadoop-yarn-applications-unmanaged-am-launcher .... SUCCESS [1.933s]
[INFO] hadoop-yarn-site .................................. SUCCESS [0.065s]
[INFO] hadoop-yarn-registry .............................. SUCCESS [3.858s]
[INFO] hadoop-yarn-project ............................... SUCCESS [3.198s]
[INFO] hadoop-mapreduce-client ........................... SUCCESS [0.047s]
[INFO] hadoop-mapreduce-client-core ...................... SUCCESS [16.565s]
[INFO] hadoop-mapreduce-client-common .................... SUCCESS [14.164s]
[INFO] hadoop-mapreduce-client-shuffle ................... SUCCESS [3.182s]
[INFO] hadoop-mapreduce-client-app ....................... SUCCESS [7.864s]
[INFO] hadoop-mapreduce-client-hs ........................ SUCCESS [4.690s]
[INFO] hadoop-mapreduce-client-jobclient ................. SUCCESS [13.117s]
[INFO] hadoop-mapreduce-client-hs-plugins ................ SUCCESS [2.374s]
[INFO] Apache Hadoop MapReduce Examples .................. SUCCESS [5.749s]
[INFO] hadoop-mapreduce .................................. SUCCESS [2.232s]
[INFO] Apache Hadoop MapReduce Streaming ................. SUCCESS [14.033s]
[INFO] Apache Hadoop Distributed Copy .................... SUCCESS [21.012s]
[INFO] Apache Hadoop Archives ............................ SUCCESS [1.938s]
[INFO] Apache Hadoop Rumen ............................... SUCCESS [4.862s]
[INFO] Apache Hadoop Gridmix ............................. SUCCESS [4.042s]
[INFO] Apache Hadoop Data Join ........................... SUCCESS [2.829s]
[INFO] Apache Hadoop Ant Tasks ........................... SUCCESS [1.852s]
[INFO] Apache Hadoop Extras .............................. SUCCESS [3.013s]
[INFO] Apache Hadoop Pipes ............................... SUCCESS [0.025s]
[INFO] Apache Hadoop OpenStack support ................... SUCCESS [3.582s]
[INFO] Apache Hadoop Amazon Web Services support ......... SUCCESS [3:18.820s]
[INFO] Apache Hadoop Azure support ....................... SUCCESS [22.789s]
[INFO] Apache Hadoop Client .............................. SUCCESS [6.038s]
[INFO] Apache Hadoop Mini-Cluster ........................ SUCCESS [0.174s]
[INFO] Apache Hadoop Scheduler Load Simulator ............ SUCCESS [5.202s]
[INFO] Apache Hadoop Tools Dist .......................... SUCCESS [9.428s]
[INFO] Apache Hadoop Tools ............................... SUCCESS [0.038s]
[INFO] Apache Hadoop Distribution ........................ SUCCESS [32.159s]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 19:13.057s
[INFO] Finished at: Thu Jan 31 01:57:41 CST 2019
[INFO] Final Memory: 93M/237M
[INFO] ------------------------------------------------------------------------
[WARNING] The requested profile "nativeN" could not be activated because it does not exist.

 

 

3.4、成功的64位hadoop包在/opt/hadoop-2.7.2-src/hadoop-dist/target下
[root@hadoop101 target]# pwd

/opt/hadoop-2.7.2-src/hadoop-dist/target

3.5、编译源码过程中常见的问题及解决方案
(1)MAVEN install时候JVM内存溢出

处理方式:在环境配置文件和maven的执行文件均可调整 MAVEN_OPT 的 heap 大小。(详情查阅MAVEN 编译 JVM调优问题,如:http://outofmemory.cn/code-snippet/12652/maven-outofmemoryerror-method)

(2)编译期间maven报错。可能网络阻塞问题导致依赖库下载不完整导致,多次执行命令(一次通过比较难):

[root@hadoop101 hadoop-2.7.2-src]#mvn package -Pdist,nativeN -DskipTests -Dtar

(3)报ant、protobuf等错误,插件下载未完整或者插件版本问题,最开始链接有较多特殊情况,同时推荐 2.7.0版本的问题汇总帖子 http://www.tuicool.com/articles/IBn63qf

 

参考:https://www.cnblogs.com/duking1991/p/6104304.html
————————————————
版权声明:本文为CSDN博主「底层_码农」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/qq_40794973/article/details/86707429

posted @ 2020-01-20 10:40  上台阶  阅读(246)  评论(0编辑  收藏  举报