Hadoop3.2.1 之编译源码(系列文章之五)

1 前期准备工作

1.    CentOS联网

配置CentOS能连接外网。Linux虚拟机ping www.baidu.com 是畅通的

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

2.    jar包准备(hadoop源码、JDK8、maven、ant 、protobuf)

1hadoop-3.2.1-src.tar.gz

2jdk-8u144-linux-x64.tar.gz

3apache-ant-1.9.14-bin.tar.gzbuild工具,打包用的)

4apache-maven-3.6.3-bin.tar.gz

5protobuf-3.11.2.zip(序列化的框架)

2 jar包安装

注意:所有操作必须在root用户下完成

  1. JDK解压、配置环境变量 JAVA_HOME和PATH,验证java-version(如下都需要验证是否配置成功)

[[email protected] software] # tar -zxf jdk-8u144-linux-x64.tar.gz -C /opt/module/

 

[[email protected] software]# vi /etc/profile

#JAVA_HOME:

export JAVA_HOME=/opt/module/jdk1.8.0_144

export PATH=$PATH:$JAVA_HOME/bin

 

[[email protected] software]#source /etc/profile

验证命令:java -version

  1. Maven解压、配置  MAVEN_HOME和PATH

[[email protected] software]# tar -zxvf apache-maven--3.6.3-bin.tar.gz -C /opt/module/

 

[[email protected] apache-maven--3.6.3]# 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>

 

[[email protected] apache-maven-3.6.3]# vi /etc/profile

#MAVEN_HOME

export MAVEN_HOME=/opt/module/apache-maven-3.6.3

export PATH=$PATH:$MAVEN_HOME/bin

 

[[email protected] software]#source /etc/profile

验证命令:mvn -version

  1. ant解压、配置  ANT _HOME和PATH

[[email protected] software]# tar -zxvf apache-ant-1.9.14-bin.tar.gz -C /opt/module/

 

[[email protected] apache-ant-1.9.14]# vi /etc/profile

#ANT_HOME

export ANT_HOME=/opt/module/apache-ant-1.9.14

export PATH=$PATH:$ANT_HOME/bin

 

[[email protected] software]#source /etc/profile

验证命令:ant -version

  1. 安装  glibc-headers 和  g++  命令如下

[[email protected] apache-ant-1.9.14]# yum install glibc-headers

[[email protected] apache-ant-1.9.14]# yum install gcc-c++

  1. 安装make和cmake

[[email protected] apache-ant-1.9.14]# yum install make

[[email protected] apache-ant-1.9.14]# yum install cmake

  1. 解压protobuf ,进入到解压后protobuf主目录,/opt/module/protobuf-3.11.2,然后相继执行命令

[[email protected] software]# tar -zxvf protobuf-3.11.2.tar.gz -C /opt/module/

[[email protected] opt]# cd /opt/module/protobuf-3.11.2/

 

[[email protected] protobuf-3.11.2]#./configure 

 

[[email protected] protobuf-3.11.2]# make 

Hadoop3.2.1 之编译源码(系列文章之五)

[[email protected] protobuf-3.11.2]# make check 

[[email protected] protobuf-3.11.2]# make install 

[[email protected] protobuf-3.11.2]# ldconfig 

 

[[email protected] hadoop-dist]# vi /etc/profile

#LD_LIBRARY_PATH

export LD_LIBRARY_PATH=/opt/module/protobuf-3.11.2

export PATH=$PATH:$LD_LIBRARY_PATH

 

[[email protected] software]#source /etc/profile

验证命令:protoc --version

  1. 安装openssl库

[[email protected] software]#yum install openssl-devel

  1. 安装 ncurses-devel库

[[email protected] software]#yum install ncurses-devel

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

3 编译源码

1.    解压源码到/opt/目录

[[email protected] software]# tar -zxvf hadoop-3.2.1-src.tar.gz -C /opt/

2.    进入到hadoop源码主目录

[[email protected] hadoop-3.2.1-src]# pwd

/opt/hadoop-3.2.1-src

3.    通过maven执行编译命令

[[email protected] hadoop-3.2.1-src]# cd /home/software/hadoop-3.2.1-src

[[email protected] hadoop-3.2.1-src]#mvn package -Pdist,native -DskipTests -Dtar

等待时间30分钟左右,最终成功是全部SUCCESS,如图2-42所示。

Hadoop3.2.1 之编译源码(系列文章之五)

 

图2-42 编译源码

4.    成功的64位hadoop包在/opt/hadoop-3.2.1-src/hadoop-dist/target下

[[email protected] target]# pwd

/opt/hadoop-3.2.1-src/hadoop-dist/target