一、下载需要的源码包(注意:我用的是非root用户)
第一步:切换到hadoop-2.7.2目录(自己的安装目录,我的是 /opt/module/hadoop-2.7.2/)
[wwt@note01 ~]$ cd /opt/module/hadoop-2.7.2/
第二步:创建native_snappy目录
[wwt@note01 hadoop-2.7.2]$ mkdir native_snappy
第三步:进入到native_snappy目录
[wwt@note01 hadoop-2.7.2]$ cd native_snappy/
第四步:下载snappy-1.1.1.tar.gz压缩包
[wwt@note01 native_snappy]$ wget http://pkgs.fedoraproject.org/repo/pkgs/snappy/snappy-1.1.1.tar.gz/8887e3b7253b22a31f5486bca3cbc1c2/snappy-1.1.1.tar.gz
如果提示:-bash: wget: command not found,说明没有安装wget,所以先安装wget,
[wwt@note01 native_snappy]$ sudo yum install -y wget
[wwt@note01 native_snappy]$ wget http://pkgs.fedoraproject.org/repo/pkgs/snappy/snappy-1.1.1.tar.gz/8887e3b7253b22a31f5486bca3cbc1c2/snappy-1.1.1.tar.gz
第五步:下载protobuf-2.5.0.tar.gz压缩包,官网已没有了,自己找相关下载链接。也可从我下边提供的百度云连接中下载。
第六步:下载hadoop-2.7.2-src.tar.gz压缩包
[wwt@note01 native_snappy]$ wget https://archive.apache.org/dist/hadoop/common/hadoop-2.7.2/hadoop-2.7.2-src.tar.gz
[wwt@note01 native_snappy]$ ll
total 21952
-rw-rw-r--. 1 wwt wwt 18290860 Jan 26 2016 hadoop-2.7.2-src.tar.gz
-rw-r--r--. 1 root root 2401901 Jul 23 2019 protobuf-2.5.0.tar.gz
-rw-rw-r--. 1 wwt wwt 1777992 Feb 24 2014 snappy-1.1.1.tar.gz
相关安装包的百度云链接
百度云链接
提取码:n9s9
二、准备编译环境
maven(maven安装)
zlib-devel
svn
autoconf
automake
libtool
cmake
ncurses-devel
openssl-devel
gcc-c++
[wwt@note01 native_snappy]$ sudo yum -y install svn autoconf automake libtool cmake ncurses-devel openssl-devel gcc*
三、编译安装snappy (用root用户执行以下命令)
[root@note01 native_snappy]# tar -zxf snappy-1.1.1.tar.gz
[root@note01 native_snappy]# cd snappy-1.1.1
[root@note01 snappy-1.1.1]# ./configure
[root@note01 snappy-1.1.1]# make
[root@note01 snappy-1.1.1]# make install
查看snappy库文件
[root@note01 snappy-1.1.1]# ls -lh /usr/local/lib | grep snappy
-rw-r--r--. 1 root root 229K Jul 2 04:28 libsnappy.a
-rwxr-xr-x. 1 root root 953 Jul 2 04:28 libsnappy.la
lrwxrwxrwx. 1 root root 18 Jul 2 04:28 libsnappy.so -> libsnappy.so.1.2.0
lrwxrwxrwx. 1 root root 18 Jul 2 04:28 libsnappy.so.1 -> libsnappy.so.1.2.0
-rwxr-xr-x. 1 root root 145K Jul 2 04:28 libsnappy.so.1.2.0
四、编译安装protobuf
[root@note01 snappy-1.1.1]# cd ..
[root@note01 native_snappy]# tar -zxf protobuf-2.5.0.tar.gz
[root@note01 native_snappy]# cd protobuf-2.5.0
[root@note01 protobuf-2.5.0]# ./configure
[root@note01 protobuf-2.5.0]# make
[root@note01 protobuf-2.5.0]# make install
五、查看protobuf版本以测试是否安装成功
[root@note01 protobuf-2.5.0]# protoc --version
libprotoc 2.5.0
六、编译hadoop native
[root@note01 protobuf-2.5.0]# cd ..
[root@note01 native_snappy]# tar -zxf hadoop-2.7.2-src.tar.gz
[root@note01 native_snappy]# cd hadoop-2.7.2-src
注意:将hadoop-2.7的pom.xml文件中的\ <requireMavenVersion>和 <requireJavaVersion>的版本改成自己安装的maven和jdk的版本:
<requireMavenVersion>
<version>3.0.5</version>
</requireMavenVersion>
<requireJavaVersion>
<version>1.8.0</version>
</requireJavaVersion>
[root@note01 hadoop-2.7.2-src]# mvn install
[root@note01 hadoop-2.7.2-src]# mvn clean package -DskipTests -Pdist,native -Dtar -Dsnappy.lib=/usr/local/lib -Dbundle.snappy
[INFO] Apache Hadoop Distribution ........................ SUCCESS [1:08.479s]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 49:36.495s
[INFO] Finished at: Thu Jul 02 08:45:26 CST 2020
[INFO] Final Memory: 174M/667M
[INFO] -------------------------------------------
执行成功后,hadoop-dist/target/hadoop-2.7.2.tar.gz即为新生成的二进制安装包
注:新生成的安装包与官网安装包的区别就是lib/native中多了一些与snappy相关的文件