环境说明:
apache-hive-1.2.2-bin
hbase-1.2.6
zookeeper-3.4.9
hadoop-2.7.3
前期说明:
Hive与HBase的整合功能的实现是利用两者本身对外的API接口互相进行通信,相互通信主要是依靠hive_hbase-handler.jar工具类
注意:以下路径以自己的路径为准
第一步:
cp hbase-1.2.6-tests.jar /home/hadoop/apache-hive-1.2.2-bin/lib/
cp zookeeper-3.4.9.jar /home/hadoop/apache-hive-1.2.2-bin/lib/
第二步:修改 hive/conf下hive-site.xml文件
cd /home/hadoop/apache-hive-1.2.2-bin/
mkdir tmp
mkdir logs
以下内容 添加到文件底部 </configuration> 之上
<!--
<property>
<name>hive.exec.scratchdir</name>
<value>/home/hadoop/apache-hive-1.2.2-bin/tmp/</value>
</property>
-->
<property>
<name>hive.querylog.location</name>
<value>/home/hadoop/apache-hive-1.2.2-bin/logs/</value>
</property>
<property>
<name>hive.aux.jars.path</name>
<value>file:///home/hadoop/apache-hive-1.2.2-bin/lib/hive-hbase-handler-1.2.2.jar,file:///home/hadoop/apache-hive-1.2.2-bin/lib/hbase-it-1.2.6.jar,file:///home/hadoop/apache-hive-1.2.2-bin/lib/hbase-common-1.2.6.jar,file:///home/hadoop/apache-hive-1.2.2-bin/lib/hbase-common-1.2.6-tests.jar
,file:///home/hadoop/apache-hive-1.2.2-bin/lib/hbase-client-1.2.6.jar,file:///home/hadoop/apache-hive-1.2.2-bin/lib/zookeeper-3.4.9.jar,file:///home/hadoop/apache-hive-1.2.2-bin/lib/hbase-protocol-1.2.6.jar,file:///home/hadoop/apache-hive-1.2.2-bin/lib/htrace-core-3.1.0-incubating.jar,file:///home/hadoop/apache-hive-1.2.2-bin/lib/netty-all-4.0.23.Final.jar,file:///home/hadoop/apache-hive-1.2.2-bin/lib/hbase-hadoop2-compat-1.2.6.jar</value>
</property>
第三步:
拷贝hbase-common-1.2.6.jar到所有节点的/usr/local/hadoop-2.7.3/share/hadoop/common下
第四步:
拷贝hbase/conf下的hbase-site.xml文件到所有节点的/usr/local/hadoop-2.7.3/hadoop/etc/hadoop下
第五步:
拷贝以下的包,到hive/lib下
cp hbase-common-1.2.6.jar hbase-common-1.2.6-tests.jar hbase-client-1.2.6.jar hbase-hadoop-compat-1.2.6.jar hbase-protocol-1.2.6.jar hbase-server-1.2.6.jar /home/hadoop/hive-1.1.0-cdh5.11.0/lib
hbase-protocol-1.2.6.jar htrace-core-3.2.0-incubating.jar netty-all-4.0.23.Final.jar hbase-hadoop2-compat-1.2.6.jar metrics-core-2.2.0.jar /home/hadoop/apache-hive-1.2.0-bin/lib/
第六步:
拷贝hbase-1.2.6.jar 到所有hadoop节点 lib下(包括master节点)
cp hbase-it-1.2.6.jar /usr/local/hadoop-2.7.3/lib/
第七步:启动hive
cd /home/hadoop/apache-hive-1.2.2-bin/bin
./hive
例子
1创建 hbase识别的表
hive>
CREATE external TABLE hbase_table_1(key int, value string)
STORED BY 'org.apache.hadoop.hive.hbase.HBaseStorageHandler'
WITH SERDEPROPERTIES ("hbase.columns.mapping"=":key,cf1:val")
TBLPROPERTIES ("hbase.table.name"="sq")
;
***(hbase.table.name 定义在hbase的table名称
hbase.columns.mapping 定义在hbase的列族)****
2.创建 hive表
hive> create table ha1(id int,name string)
row format delimited
fields terminated by '\t'
stored as textfile;
[hadoop@h91 ~]$ vi ha1.txt
11 zs
22 ls
33 ww
hive> load data local inpath '/home/hadoop/ha1.txt' into table ha1;
hive> insert into table hbase_table_1 select * from ha1;
~~hive> select * from hbase_table_1;
3.[hadoop@h91 hbase-1.2.6]$ bin/hbase shell
hbase(main):002:0> scan 'sq'
(能看到结果 说明hive把数据存到hbase中)