Centos7编译Hadoop源码
jar包安装
注意:所有操作必须在root用户下完成
1 JDK解压、配置环境变量 JAVA_HOME和PATH,验证java-version(如下都需要验证是否配置成功)
[root@192 opt]# mkdir /opt/module/ [root@192 opt]# tar -zxf jdk-8u144-linux-x64.tar.gz -C /opt/module/ [root@192 opt]# ll 总用量 211912 -rw-r--r-- 1 root root 5635116 1月 15 20:00 apache-ant-1.9.9-bin.tar.gz -rw-r--r-- 1 root root 5144659 1月 15 20:00 apache-maven-3.0.5-bin.tar.gz -rw-r--r-- 1 root root 18290860 1月 15 20:00 hadoop-2.7.2-src.tar.gz -rw-r--r-- 1 root root 185515842 1月 15 20:02 jdk-8u144-linux-x64.tar.gz drwxr-xr-x 3 root root 26 1月 15 20:03 module -rw-r--r-- 1 root root 2401901 1月 15 20:00 protobuf-2.5.0.tar.gz drwxr-xr-x. 2 root root 6 10月 31 2018 rh [root@192 opt]# vi /etc/profile [root@192 opt]# source /etc/profile [root@192 opt]# java -version openjdk version "1.8.0_232" OpenJDK Runtime Environment (build 1.8.0_232-b09) OpenJDK 64-Bit Server VM (build 25.232-b09, mixed mode)
验证命令:java -version
2 Maven解压、配置 MAVEN_HOME和PATH
[root@192 opt]# tar -zxvf apache-maven-3.0.5-bin.tar.gz -C /opt/module/ apache-maven-3.0.5/LICENSE.txt apache-maven-3.0.5/NOTICE.txt apache-maven-3.0.5/README.txt apache-maven-3.0.5/bin/m2.conf
[root@192 apache-maven-3.0.5]# vi conf/settings.xml [root@192 apache-maven-3.0.5]# vim conf/settings.xml [root@192 apache-maven-3.0.5]# vi /etc/profile [root@192 apache-maven-3.0.5]# source /etc/profile [root@192 apache-maven-3.0.5]# mvn -version Apache Maven 3.0.5 (r01de14724cdef164cd33c7c8c2fe155faf9602da; 2013-02-19 21:51:28+0800) 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: zh_CN, platform encoding: UTF-8 OS name: "linux", version: "3.10.0-1062.9.1.el7.x86_64", arch: "amd64", family: "unix"
<mirror> <id>nexus-aliyun</id> <mirrorOf>central</mirrorOf> <name>Nexus aliyun</name> <url>http://maven.aliyun.com/nexus/content/groups/public</url> </mirror>
验证命令:mvn -version
3 ant解压、配置 ANT _HOME和PATH
[root@192 opt]# tar -zxvf apache-ant-1.9.9-bin.tar.gz -C /opt/module/ apache-ant-1.9.9/bin/ant apache-ant-1.9.9/bin/antRun apache-ant-1.9.9/bin/antRun.pl apache-ant-1.9.9/bin/complete-ant-cmd.pl apache-ant-1.9.9/bin/runant.pl apache-ant-1.9.9/bin/runant.py apache-ant-1.9.9/ apache-ant-1.9.9/bin/ apache-ant-1.9.9/etc/ apache-ant-1.9.9/etc/checkstyle/ apache-ant-1.9.9/lib/ apache-ant-1.9.9/manual/ apache-ant-1.9.9/manual/Integration/ apache-ant-1.9.9/manual/Tasks/
[root@192 opt]# vi /etc/profile [root@192 opt]# source /etc/profile
export ANT_HOME=/opt/module/apache-ant-1.9.9 export PATH=$PATH:$ANT_HOME/bin
验证命令:ant -version
4 安装 glibc-headers 和 g++ 命令如下
[root@hadoop101 apache-ant-1.9.9]# yum install glibc-headers [root@hadoop101 apache-ant-1.9.9]# yum install gcc-c++
安装make和cmake
[root@hadoop101 apache-ant-1.9.9]# yum install make [root@hadoop101 apache-ant-1.9.9]# yum install cmake
解压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
安装openssl库
[root@hadoop101 software]#yum install openssl-devel
安装 ncurses-devel库
[root@hadoop101 software]#yum install ncurses-devel
到此,编译工具安装基本完成。
编译源码
1. 解压源码到/opt/目录
[root@hadoop101 software]# tar -zxvf hadoop-2.7.2-src.tar.gz -C /opt/
2. 进入到hadoop源码主目录
[root@hadoop101 hadoop-2.7.2-src]# pwd /opt/hadoop-2.7.2-src
3. 通过maven执行编译命令
[root@hadoop101 hadoop-2.7.2-src]#mvn package -Pdist,native -DskipTests -Dtar
最终编译了5个小时。