一.Hadoop支持Snappy
2.查看libsnappy.so.1.2.0
[root@sht-sgmhadoopnn-01 ~]#ll $HADOOP_HOME/lib/native/
total 4880
-rw-r--r-- 1 root root 1211196 Jun 21 19:11 libhadoop.a
-rw-r--r-- 1 root root 1485756 Jun 21 19:12 libhadooppipes.a
lrwxrwxrwx 1 root root18 Jun
21 19:45 libhadoop.so -> libhadoop.so.1.0.0
-rwxr-xr-x 1 root root717060 Jun
21 19:11 libhadoop.so.1.0.0
-rw-r--r-- 1 root root582128 Jun
21 19:12 libhadooputils.a
-rw-r--r-- 1 root root365052 Jun
21 19:11 libhdfs.a
lrwxrwxrwx 1 root root16 Jun
21 19:45 libhdfs.so -> libhdfs.so.0.0.0
-rwxr-xr-x 1 root root229289 Jun
21 19:11 libhdfs.so.0.0.0
-rw-r--r-- 1 root root233538 Jun
21 19:11 libsnappy.a
-rwxr-xr-x 1 root root953 Jun
21 19:11 libsnappy.la
lrwxrwxrwx 1 root root18 Jun
21 19:45 libsnappy.so -> libsnappy.so.1.2.0
lrwxrwxrwx 1 root root18 Jun
21 19:45 libsnappy.so.1 -> libsnappy.so.1.2.0
-rwxr-xr-x 1 root
root147726 Jun 21 19:11 libsnappy.so.1.2.0
[root@sht-sgmhadoopnn-01 ~]#
###假如集群已经安装好
3.修改$HADOOP_HOME/etc/hadoop/hadoop-env.sh,添加
export
HADOOP_OPTS="$HADOOP_OPTS-Djava.library.path=$HADOOP_HOME/lib:$HADOOP_HOME/lib/native"
############会解决Warn:””################################################
[root@sht-sgmhadoopnn-01 ~]# hadoop fs -ls /
16/06/21 15:08:24 WARN util.NativeCodeLoader:
Unable to load native-hadoop library for your platform... usingbuiltin-java classes where applicable
##################################################################################################
4.修改$HADOOP_HOME/etc/hadoop/core-site.xml
点击(此处)折叠或打开
io.compression.codecs
org.apache.hadoop.io.compress.GzipCodec,
org.apache.hadoop.io.compress.DefaultCodec,
org.apache.hadoop.io.compress.BZip2Codec,
org.apache.hadoop.io.compress.SnappyCodec
5.修改$HADOOP_HOME/etc/hadoop/mapred-site.xml中有关压缩属性,测试snappy
点击(此处)折叠或打开
mapreduce.map.output.compress
true
mapreduce.map.output.compress.codec
org.apache.hadoop.io.compress.SnappyCodec
6.新增$HADOOP_HOME/etc/hadoop/yarn-site.xml(是否启用日志聚集功能、yarn日志服务的地址、配置yarn的memory和cpu)
点击(此处)折叠或打开
yarn.log-aggregation-enable
true
yarn.log.server.url
http://sht-sgmhadoopnn-01:19888/jobhistory/logs
yarn.nodemanager.resource.memory-mb
10240
yarn.scheduler.minimum-allocation-mb
1500
单个任务可申请最少内存,默认1024MB
yarn.scheduler.maximum-allocation-mb
2500
单个任务可申请最大内存,默认8192MB
yarn.nodemanager.resource.cpu-vcores
2
7.将hadoop-env.sh,core-site.xml,mapred-site.xml,yarn-site.xml同步到集群其他节点
8.重启Hadoop集群
9.验证1:
hadoop checknative
[root@sht-sgmhadoopnn-01 ~]#hadoop
checknative
16/06/25 12:58:13 WARN bzip2.Bzip2Factory: Failed to load/initialize
native-bzip2 library system-native, will use pure-Java version
16/06/25 12:58:13 INFO zlib.ZlibFactory: Successfully loaded &
initialized native-zlib library
Native library checking:
hadoop:true
/hadoop/hadoop-2.7.2/lib/native/libhadoop.so.1.0.0
zlib:true
/usr/local/lib/libz.so.1
snappy:true
/hadoop/hadoop-2.7.2/lib/native/libsnappy.so.1
lz4:true revision:99
bzip2:false
openssl: true /usr/lib64/libcrypto.so
[root@sht-sgmhadoopnn-01 ~]#
####支持本地native,支持snappy
10.验证2
[root@sht-sgmhadoopnn-01 ~]#vi test.log
a
c d
c d d d a
1 2
a
[root@sht-sgmhadoopnn-01 ~]#hadoop
fs -mkdir /input
[root@sht-sgmhadoopnn-01 ~]#hadoop
fs -put test.log /input/
[root@sht-sgmhadoopnn-01 ~]#hadoop
jar /hadoop/hadoop/share/hadoop/mapreduce/hadoop-mapreduce-examples-*.jar
wordcount /input /output1
为了验证是否成功,往hdfs上传一个文本文件,敲入一些词组,运行wordcount程序。如果map部分100%完成,即说明我们hadoop snappy安装成功。
因为hadoop没有像HBase一样提供util.CompressionTest类(或者是我没有找到),所以只能按照这种方法来测试。接下来,将详细列出HBase使用Snappy的配置过程。
二.HBase支持Snappy
1.复制hadoop的native文件夹至hbase的lib目录下
[root@sht-sgmhadoopnn-01 ~]#cp -r $HADOOP_HOME/lib/native $HBASE_HOME/lib/
2.修改$HBASE_HOME/conf/hbase-env.sh,添加
export
LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$HADOOP_HOME/lib/native/
export HBASE_LIBRARY_PATH=$HBASE_LIBRARY_PATH:$HBASE_HOME/lib/native/
3.将hbase-env.sh同步到集群其他节点
4.重启Hbase集群
5.验证1:
hbase org.apache.hadoop.hbase.util.CompressionTest
hdfs://mycluster/output1/part-r-00000 snappy
[root@sht-sgmhadoopnn-01 ~]#hbase
org.apache.hadoop.hbase.util.CompressionTest
hdfs://mycluster/output1/part-r-00000 snappy
#使用CompressionTest来查看snappy是否enabled并且能成功loaded.
/output1/part-r-00000为我们在验证hadoop snappy的时候,wordcount的输出
6.验证2:建表和put插入数据
点击(此处)折叠或打开
hbase(main):004:0>create'test_snappy',{NAME => 'f',COMPRESSION=> 'snappy'}
0 row(s) in2.2570 seconds
=>Hbase::Table-tsnappy0
hbase(main):005:0>put' test_snappy'', 'row1', 'f:col1', 'value