软件版本:hadoop2.7.2 hbase1.1.13
操作系统 :centos 7
软件环境:jdk8
Snappy是一个压缩/解压库。它不针对最大压缩,或与任何其他压缩库的兼容性;相反,它的目标是非常高的速度和合理的压缩。例如,与zlib的最快模式相比,Snappy对于大多数输入来说要快一个数量级,但是压缩后的文件要大20%到100%。(有关更多信息,请参见下面的“性能”。)Snappy具有以下特性:快速:压缩速度为250mb /s以上,不需要汇编代码。
一、环境准备
1、安装yum依赖
yum install -y automake autoconf gcc-c++ cmake libedit libtool openssl-devel ncurses-devel
2、安装maven
yum install wget -y
wget http://mirror.bit.edu.cn/apache/maven/maven-3/3.5.4/binaries/apache-maven-3.5.4-bin.tar.gz
tar xvf apache-maven-3.5.4-bin.tar.gz -C /opt/
ln -s /opt/apache-maven-3.5.4 /opt/apps/maven
配置环境变量
vi /etc/profile
export M2_HOME=/opt/apps/maven
export PATH=$PATH:$M2_HOME/bin
#环境变量生效
source /etc/profile
二、安装SNAPPY相关组件
需要相关包如下:
hadoop源码包:hadoop2.7.2 下载地址
snappy安装包:snappy1.1.3 下载地址
protobuf安装包:protobuf-2.6.2 下载地址官网不提供旧版本下载,2.5.0百度网盘下载
实际安装使用protobuf-2.5.0 (推荐),protobuf-2.6.2未测试与hadoop2.7的兼容性
1、安装snappy
wget https://src.fedoraproject.org/repo/pkgs/snappy/snappy-1.1.3.tar.gz/7358c82f133dc77798e4c2062a749b73/snappy-1.1.3.tar.gz
tar xvf snappy-1.1.3.tar.gz -C /opt/
cd /opt/snappy-1.1.3
./configure
make
make install
#卸载命令 make uninstall
忽视如下打印信息,不造成影响
make[1]: Leaving directory `/opt/apps/snappy-1.1.3'
验证安装完成
ll /usr/local/lib/ | grep snappy
如下所示安装成功
2、安装protobuf
#wget http://sourceforge.net/projects/protobuf/files/protobuf-2.6.0.tar.gz/download -O protobuf-2.6.0.tar.gz
tar xvf protobuf-2.5.0.tar.gz -C /opt/
cd /opt/protobuf-2.5.0/
./autogen.sh
./configure
make
make install
#卸载命令 make uninstall
忽视如下打印信息,不造成影响
make[1]: Leaving directory `xxxxxxx'
验证安装完成
protoc --version
3、编译hadoop源码中hadoop-common模块
已编译好的结果https://pan.baidu.com/s/1mObt-7weCNyiOk_0hKEO3A直接下载,可以省去编译hadoop的麻烦。环境要求hadoop2.7.2,jdk8
编译之前先修改maven下载镜像,否则编译时无法下载相应的Tomcat报错
vi /opt/apps/maven/conf/settings.xml
alimaven
aliyun maven
http://maven.aliyun.com/nexus/content/groups/public/
central
下载编译hadoop源码
wget http://archive.apache.org/dist/hadoop/core/hadoop-2.7.2/hadoop-2.7.2-src.tar.gz
tar xvf hadoop-2.7.2-src.tar.gz -C /opt/
cd /opt/hadoop-2.7.2-src
export MAVEN_OPTS="-Xms256m -Xmx512m"
mvn package -Pdist,native -DskipTests -Dtar -rf :hadoop-common -Drequire.snappy -X
#若重新编译
#mvn clean package -Pdist,native -DskipTests -Dtar -rf :hadoop-common -Drequire.snappy -X
查看编译结果
[root@hdc-data4 hadoop-2.7.2-src]# ls hadoop-dist/target/hadoop-2.7.2/lib/native/
libhadoop.a libhadooppipes.a libhadoop.so libhadoop.so.1.0.0 libhadooputils.a libhdfs.a libhdfs.so libhdfs.so.0.0.0
4、在hadoop安装目录添加snappy支持
将编译结果 hadoop-dist/target/hadoop-2.7.2/lib/native/下的所有文件拷贝到hadoop安装目录下lib/native/
cp -r /opt/hadoop-2.7.2-src/hadoop-dist/target/hadoop-2.7.2/lib/native/* /opt/apps/hadoop/lib/native/
#分发到集群
scp -r /opt/apps/hadoop/lib/native/* root@hdc-data5:/opt/apps/hadoop/lib/native/
scp -r /opt/apps/hadoop/lib/native/* root@hdc-data6:/opt/apps/hadoop/lib/native/
修改core-site.xml,添加
io.compression.codecs
org.apache.hadoop.io.compress.SnappyCodec
修改yarn-site.xml , 添加
mapreduce.map.output.compress
true
mapred.map.output.compress.codec
org.apache.hadoop.io.compress.SnappyCodec
将修改的配置同步到集群
scp -r /opt/apps/hadoop/etc/hadoop/core-site.xml root@hdc-data5:/opt/apps/hadoop/etc/hadoop/
scp -r /opt/apps/hadoop/etc/hadoop/core-site.xml root@hdc-data6:/opt/apps/hadoop/etc/hadoop/
scp -r /opt/apps/hadoop/etc/hadoop/yarn-site.xml root@hdc-data5:/opt/apps/hadoop/etc/hadoop/
scp -r /opt/apps/hadoop/etc/hadoop/yarn-site.xml root@hdc-data6:/opt/apps/hadoop/etc/hadoop/
验证
hadoop checknative -a
结果如下:
5、HBase 配置Snappy及验证
mkdir -p /opt/apps/hbase/lib/native/Linux-amd64-64
cp -r /opt/apps/hadoop/lib/native/* /opt/apps/hbase/lib/native/Linux-amd64-64/
修改 hbase-env.sh,添加
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$HADOOP_HOME/lib/native/:/usr/local/lib/
export HBASE_LIBRARY_PATH=$HBASE_LIBRARY_PATH:$HBASE_HOME/lib/native/Linux-amd64-64/:/usr/local/lib/
export CLASSPATH=$CLASSPATH:$HBASE_LIBRARY_PATH
修改hbase-site.xml,添加
hbase.regionserver.codecs
snappy
- 同步配置到HBASE集群
重启服务及测试
touch /tmp/a
hbase org.apache.hadoop.hbase.util.CompressionTest /tmp/a snappy
bin/hbase shell
create 'tsnappy',{ NAME => 'f', COMPRESSION => 'snappy'}