本文介绍hadoop 3.1.4版本在centos 7的环境中编译步骤。
本示例是以root用户进行操作的,如果非root用户可能会需要root权限。
目录
一、前提
1、查看操作系统能够版本
- # 查看操作系统版本:
- cat /etc/issue
2、准备好编译所需要的环境
apache-maven-3.5.4-bin.tar.gz
cmake-3.13.5.tar.gz
protobuf-2.5.0.tar.gz
snappy-1.1.3.tar.gz
jdk-8u65-linux-x64.tar.gz
hadoop-3.1.4-src.tar.gz
3、网络可以连接外网
二、操作步骤
1、安装gcc相关
- 1、yum install gcc gcc-c++ -y
-
- #下面这个命令不需要执行 手动安装cmake
- 2、yum install make cmake #(这里cmake版本推荐为3.6版本以上,版本低源码无法编译!可手动安装)
-
- 3、yum install autoconf automake libtool curl -y
-
- 4、yum install lzo-devel zlib-devel openssl openssl-devel ncurses-devel -y
-
- 5、yum install snappy snappy-devel bzip2 bzip2-devel lzo lzo-devel lzop libXtst -y
2、手动安装cmake
- # yum卸载已安装cmake 版本低
- yum erase cmake
-
- # 解压
- tar zxvf cmake-3.13.5.tar.gz
-
- # 编译安装
- cd /home/alanchan/tools/cmake-3.13.5
-
- ./configure
-
- make && make install
-
- # 验证
- [root@dev-525 ~]# cmake -version
- cmake version 3.13.5
-
- #如果没有正确显示版本 请断开SSH连接 重新登录
3、手动安装snappy
- # 卸载已经安装的
- cd /usr/local/lib
-
- rm -rf libsnappy*
-
- # 上传解压
- tar zxvf snappy-1.1.3.tar.gz
-
- #编译安装
- cd /home/alanchan/tools/snappy-1.1.3
-
- ./configure
-
- make && make install
-
- #验证是否安装
- [root@dev-525 ~]# ls -lh /usr/local/lib |grep snappy
- -rw-r--r-- 1 root root 511K Sep 27 14:59 libsnappy.a
- -rwxr-xr-x 1 root root 955 Sep 27 14:59 libsnappy.la
- lrwxrwxrwx 1 root root 18 Sep 27 14:59 libsnappy.so -> libsnappy.so.1.3.0
- lrwxrwxrwx 1 root root 18 Sep 27 14:59 libsnappy.so.1 -> libsnappy.so.1.3.0
- -rwxr-xr-x 1 root root 253K Sep 27 14:59 libsnappy.so.1.3.0
4、安装配置JDK 1.8
- # 解压安装包
- tar zxvf jdk-8u65-linux-x64.tar.gz
-
- # 配置环境变量
- vim /etc/profile
-
- export JAVA_HOME=/home/alanchan/tools/jdk1.8.0_65
- export PATH=$PATH:$JAVA_HOME/bin
- export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
-
- source /etc/profile
-
- # 验证是否安装成功
- java -version
-
- java version "1.8.0_65"
- Java(TM) SE Runtime Environment (build 1.8.0_65-b17)
- Java HotSpot(TM) 64-Bit Server VM (build 25.65-b01, mixed mode)
- You have new mail in /var/spool/mail/root
5、安装配置maven
- # 解压安装包
- tar zxvf apache-maven-3.5.4-bin.tar.gz
-
- # 配置环境变量
- vim /etc/profile
-
- export MAVEN_HOME=/home/alanchan/tools/apache-maven-3.5.4
- export MAVEN_OPTS="-Xms4096m -Xmx4096m"
- export PATH=:$MAVEN_HOME/bin:$PATH
-
- source /etc/profile
-
- # 验证是否安装成功
- [root@dev-525 ~]# mvn -v
- Apache Maven 3.5.4 (1edded0938998edf8bf061f1ceb3cfdeccf443fe; 2018-06-18T02:33:14+08:00)
- Maven home: /home/alanchan/tools/apache-maven-3.5.4
- Java version: 1.8.0_65, vendor: Oracle Corporation, runtime: /home/alanchan/tools/jdk1.8.0_65/jre
- Default locale: en_US, platform encoding: UTF-8
- OS name: "linux", version: "3.10.0-1160.el7.x86_64", arch: "amd64", family: "unix"
-
-
- # 添加maven 阿里云仓库地址加快国内编译速度,也可以不添加
- vim /home/alanchan/tools/apache-maven-3.5.4/conf/settings.xml
-
-
- <id>alimaven
-
aliyun maven -
http://maven.aliyun.com/nexus/content/groups/public/ -
central -
6、安装ProtocolBuffer 2.5.0
- # 解压
- tar zxvf protobuf-2.5.0.tar.gz
-
- # 编译安装
- cd /home/alanchan/tools/protobuf-2.5.0
- ./configure
- make && make install
-
- #验证是否安装成功
- [root@dev-525 ~]# protoc --version
- libprotoc 2.5.0
7、编译hadoop
- # 上传解压源码包
- tar zxvf hadoop-3.1.4-src.tar.gz
-
- # 编译
- cd /home/alanchan/tools/hadoop-3.1.4-src
-
- mvn clean package -Pdist,native -DskipTests -Dtar -Dbundle.snappy -Dsnappy.lib=/usr/local/lib
-
- # 参数说明:
-
- Pdist,native :把重新编译生成的hadoop动态库;
- DskipTests :跳过测试
- Dtar :最后把文件以tar打包
- Dbundle.snappy :添加snappy压缩支持【默认官网下载的是不支持的】
- Dsnappy.lib=/usr/local/lib :指snappy在编译机器上安装后的库路径
8、编译之后的安装包路径
该步骤耗时较长
- /home/alanchan/tools/hadoop-3.1.4-src/hadoop-dist/target
-
- hadoop-3.1.4.tar.gz是编译后的文件
- ...
- [INFO] Apache Hadoop Distribution ......................... SUCCESS [ 24.064 s]
- [INFO] Apache Hadoop Client Modules ....................... SUCCESS [ 0.029 s]
- [INFO] Apache Hadoop Cloud Storage ........................ SUCCESS [ 0.625 s]
- [INFO] Apache Hadoop Cloud Storage Project 3.1.4 .......... SUCCESS [ 0.028 s]
- [INFO] ------------------------------------------------------------------------
- [INFO] BUILD SUCCESS
- [INFO] ------------------------------------------------------------------------
- [INFO] Total time: 52:02 min
- [INFO] Finished at: 2022-09-28T10:07:39+08:00
- [INFO] ------------------------------------------------------------------------
- [root@dev-525 ~]# cd /home/alanchan/tools/hadoop-3.1.4-src/hadoop-dist/target
- [root@dev-525 target]# ll
- total 295948
- drwxr-x--- 2 chenwei root 28 Sep 28 10:07 antrun
- drwxr-x--- 3 chenwei root 22 Sep 28 10:07 classes
- drwxr-x--- 9 chenwei root 149 Sep 28 10:07 hadoop-3.1.4
- -rw-r----- 1 chenwei root 303048995 Sep 28 10:07 hadoop-3.1.4.tar.gz
- drwxr-x--- 3 chenwei root 22 Sep 28 10:07 maven-shared-archive-resources
- drwxr-x--- 3 chenwei root 22 Sep 28 10:07 test-classes
- drwxr-x--- 2 chenwei root 6 Sep 28 10:07 test-dir
以上,完成了hadoop的源码编译,另外需要提醒的是,选好环境,否则因为环境会将人弄得精疲力尽。
评论记录:
回复评论: