Hadoop源码编译

准备

  • Hadoop源码:hadoop-2.8.1-src.tar.gz (以hadoop 2.8.1为例)
  • JDK安装包:jdk-8u45-linux-x64.gz
  • Maven安装包:apache-maven-3.3.9-bin.zip
  • 其他依赖:ProtoBuf、FindBugs、openssl、snappy

Hadoop源码准备

[root@hadoop001 sourcecode]# cd /opt
[root@hadoop001 sourcecode]# mkdir /opt/sourcecode
[root@hadoop001 sourcecode]# rz (选择hadoop-2.8.1-src.tar.gz 包的位置,上传包)
[root@hadoop001 sourcecode]# tar -xzvf hadoop-2.8.1-src.tar.gz
[root@hadoop001 sourcecode]# ll
Hadoop源码编译
[root@hadoop001 sourcecode]# cd hadoop-2.8.1-src
[root@hadoop001 hadoop-2.8.1-src]# ll
Hadoop源码编译
[root@hadoop001 hadoop-2.8.1-src]# cat BUILDING.txt
Hadoop源码编译
(BUILDING.txt 文件中也可以看到本版本编译的软件要求,Unix System+JDK1.7++Maven 3.0 or later+ProtocolBuffer 2.5.0 是必要条件,其他有if标签的,可以根据需要选择)

JAVA安装

[root@hadoop001 ~]# mkdir -p /usr/java
[root@hadoop001 ~]# cd /usr/java
[root@hadoop001 java]# rz (上传jdk-8u45-linux-x64.gz)
[root@hadoop001 java]# tar -xzvf jdk-8u45-linux-x64.gz
[root@hadoop002 java]# ll
Hadoop源码编译
[root@hadoop002 java]# chown -R root:root jdk1.8.0_45 (修改用户和用户组)
[root@hadoop002 java]# ll
Hadoop源码编译
[root@hadoop001 java]# vi /etc/profile (配置环境变量JAVA_HOME)
export JAVA_HOME=/usr/java/jdk1.8.0_45
export PATH=$JAVA_HOME/bin:$PATH
:wq
[root@hadoop001 java]# source /etc/profile
[root@hadoop001 java]# which java
Hadoop源码编译
[root@hadoop001 java]# java -version
Hadoop源码编译

Maven安装

[root@hadoop001 ~]# mkdir -p /opt/software
[root@hadoop001 ~]# cd /opt/software/
[root@hadoop001 software]# rz (上传apache-maven-3.3.9-bin.zip)
[root@hadoop001 software]# unzip apache-maven-3.3.9-bin.zip
[root@hadoop001 software]# vi /etc/profile
export MAVEN_HOME=/opt/software/apache-maven-3.3.9
export MAVEN_OPTS="-Xms256m -Xmx512m"
export PATH=$MAVEN_HOME/bin:$JAVA_HOME/bin:$PATH
:wq
[root@hadoop001 ~]# mvn -version
Hadoop源码编译

protobuf安装

[root@hadoop001 software]# rz (#上传apache-maven-3.3.9-bin.zip)
[root@hadoop001 software]# tar -zxvf protobuf-2.5.0.tar.gz
[root@hadoop001 software]# cd protobuf-2.5.0
[root@hadoop001 protobuf-2.5.0]# yum install -y gcc gcc-c++ make cmake #已经安装cmake
[root@hadoop001 protobuf-2.5.0]# ./configure --prefix=/usr/local/protobuf
[root@hadoop001 protobuf-2.5.0]# make && make install
[root@hadoop001 protobuf-2.5.0]# vi /etc/profile
export PROTOC_HOME=/usr/local/protobuf
export PATH=$PROTOC_HOME/bin:$MAVEN_HOME/bin:$JAVA_HOME/bin:$PATH
:wq
[root@hadoop001 protobuf-2.5.0]# source /etc/profile
[root@hadoop001 protobuf-2.5.0]# protoc --version
libprotoc 2.5.0

Findbugs安装

[root@hadoop001 software]# rz (上传findbugs-1.3.9.zip)
[root@hadoop001 software]# unzip findbugs-1.3.9.zip
[root@hadoop002 software]# vi /etc/profile
export FINDBUGS_HOME=/opt/software/findbugs-1.3.9
export PATH=$FINDBUGS_HOME/bin:$PROTOC_HOME/bin:$MAVEN_HOME/bin:$JAVA_HOME/bin:$PATH
[root@hadoop001 software]# source /etc/profile
[root@hadoop001 software]# findbugs -version
1.3.9

其他依赖

yum install -y openssl openssl-devel svn ncurses-devel zlib-devel libtool
yum install -y snappy snappy-devel bzip2 bzip2-devel lzo lzo-devel lzop autoconf automake

开始编译

[root@hadoop001 sourcecode]# cd hadoop-2.8.1-src
[root@hadoop001 hadoop-2.8.1-src]# mvn clean package -Pdist,native -DskipTests -Dtar

备注:

  • 编译前,先查看本机上是否安装了hadoop
    find / -name hadoop
  • 加快编译速度的小技巧:
    在maven的config文件夹下的setting.xml中加入阿里云的mirro
<mirror>
    <id>nexus-aliyun</id>
    <mirrorOf>*</mirrorOf>
    <name>Nexus aliyun</name>
    <url>http://maven.aliyun.com/nexus/content/groups/public</url >
</mirror>

    再执行以下命令进行编译
mvn clean package -Pdist -Dtar -Dmaven.javadoc.skip=true -DskipTests -fail-at-end -Pnative

get编译后的包

/opt/sourcecode/hadoop-2.8.1-src/hadoop-dist/target/hadoop-2.8.1.tar.gz

备注:
有时候编译过程中会出现下载某个包的时间太久,这是由于连接网站的过程中会出现假死,此时按ctrl+c,退出后,再重新执行编译命令即可。

相关推荐