原文链接:开启hadoop和Hbase集群的lzo压缩功能
问题导读:
1.如何启动hadoop、hbase集群的压缩功能?
2.lzo的作用是什么?
3.hadoop配置文件需要做哪些修改?
首先我们明白一个概念:
LZO 是致力于解压速度的一种数据压缩算法,LZO 是 Lempel-Ziv-Oberhumer 的缩写。
安装前:
# yum -y install lzo-devel zlib-devel gcc autoconf automakelibtool
lzo-2.06.tar.gz下载地址:Index of /opensource/lzo/download
tar -zxvf lzo-2.06.tar.gz
cd lzo-2.06
# export CFLAGS=-m64 注:如果为32位系统改为export CFLAGS=-m32
#./configure --enable-shared
# make
# make install
库文件被默认安装到了/usr/local/lib,我们需要进一步指定lzo库文件的路径,两个方法都可以:
1) 拷贝/usr/local/lib目录下的lzo库文件到/usr/lib(32位平台),或/usr/lib64(64位平台)
- #cp /usr/local/lib/liblzo2.* /usr/lib64
2)在/etc/ld.so.conf.d/目录下新建lzo.conf文件,写入lzo库文件的路径,然后运行/sbin/ldconfig -v,使配置生效
- #vi /etc/ld.so.conf.d/lzo.conf
- /usr/local/lib
- # /sbin/ldconfig -v
2. 编译安装Hadoop Lzo本地库以及Jar包,这里采用twitter维护的,从这里下载
https://github.com/twitter/hadoop-lzo
修改pom.xml:
- <properties>
- <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
- <hadoop.current.version>2.1.0-beta</hadoop.current.version>
- <hadoop.old.version>1.0.4</hadoop.old.version>
- </properties>
修改为
- <properties>
- <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
- <hadoop.current.version>2.2.0</hadoop.current.version>
- <hadoop.old.version>1.0.4</hadoop.old.version>
- </properties>
hadoop-lzo-master.zip
- cd hadoop-lzo-master
- export CFLAGS=-m64 注:如果为32位系统改为export CFLAGS=-m32
- export CXXFLAGS=-m64 注:如果为32位系统改为export CXXFLAGS=-m32
- export C_INCLUDE_PATH=/usr/local/include/lzo
- export LIBRARY_PATH=/usr/local/lib
- mvn clean package -Dmaven.test.skip=true
接着把target/native/Linux-amd64-64/lib下的全部文件拷贝到${HADOOP_HOME}/lib/native,或者
- cp /build/native/Linux-amd64-64/lib/* $HADOOP_HOME/lib/native/
- cp target/hadoop-lzo-0.4.20-SNAPSHOT.jar /opt/hadoop-2.2.0/share/hadoop/common/lib
对于Hbase启用LZO
- cp $HADOOP_HOME/lib/native/Linux-amd64-64/* $HBASE_HOME/lib/native/Linux-amd64-64
- export HBASE_LIBRARY_PATH=$HBASE_LIBRARY_PATH:$HBASE_HOME/lib/native/Linux-amd64-64/:/usr/local/lib/
同步hadoop 和hbase集群
3.配置文件修改
在hadoop-env.sh中加入
- export JAVA_LIBRARY_PATH=$HADOOP_HOME/lib/native
core-site.xml
- <!-- 配置 Hadoop压缩包 -->
- <property>
- <name>io.compression.codecs</name><value>org.apache.hadoop.io.compress.DefaultCodec,org.apache.hadoop.io.compress.GzipCodec,org.apache.hadoop.io.compress.BZip2Codec,com.hadoop.compression.lzo.LzoCodec,com.hadoop.compression.lzo.LzopCodec</value>
- </property>
- <property>
- <name>io.compression.codec.lzo.class</name>
- <value>com.hadoop.compression.lzo.LzoCodec</value>
- </property>
mapred-site.xml
- <property>
- <name>mapred.compress.map.output</name>
- <value>true</value>
- </property>
- <property>
- <name>mapred.map.output.compression.codec</name>
- <value>com.hadoop.compression.lzo.LzoCodec</value>
- </property>
- <property>
- <name>mapred.child.env</name>
- <value>LD_LIBRARY_PATH=/usr/local/lib</value>
- </property>
同步hadoop-env.sh,core-site.xml, mapred-site.xml到集群
4. 安装lzop
下载地址:http://www.lzop.org/download/
LZOP是使用lzo库写的一个程序,通过shell命令直接可以压缩、解压缩文件。
- tar zxvf lzop-1.03.tar.gz
- cd
- # exportLD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib
- # ./configure
- # make
- # makeinstall
用一下lzop的压缩解压功能,成功安装后可直接使用lzop命令对文件进行解压缩操作了。
# 压缩
- [hadoop@master1 ~]$ lzop -v test1.txt
- compressing test1.txt into test1.txt.lzo
#上传到hdfs
- [hadoop@master1 ~]$ hadoop fs -put *.lzo /in
#给Lzo文件建立Index
- hadoop
jar/opt/hadoop-2.2.0/share/hadoop/common/lib/hadoop-lzo-0.4.20-SNAPSHOT.jarcom.hadoop.compression.lzo.LzoIndexer
/in
#运行一个wordcount程序
- hadoop jar /home/hadoop/wordcount.jar org.apache.hadoop.examples.WordCount /input1 /out1
正常:
14/02/23 18:53:14 INFOlzo.GPLNativeCodeLoader: Loaded native gpl library from the embedded binaries
14/02/23 18:53:14 INFO lzo.LzoCodec:Successfully loaded &
initialized native-lzo library [hadoop-lzo
rev478aa845e11bbbeeb9b8326e733cd20a06d2cb3a]