一 、简介
Hive是基于Hadoop的一个数据仓库工具,可以将结构化的数据文件映射为一张数据库表,并提供完整的sql查询功能,可以将sql语句转换为MapReduce任务进行运行。 其优点是学习成本低,可以通过类SQL语句快速实现简单的MapReduce统计,不必开发专门的MapReduce应用,十分适合数据仓库的统计分析。
Hive与HBase的整合功能的实现是利用两者本身对外的API接口互相进行通信,相互通信主要是依靠hive_hbase-handler.jar工具类, 大致意思如图所示:
二、安装步骤:
1 .Hadoop和Hbase都已经成功安装了
Hadoop集群配置:http://blog.csdn.net/hguisu/article/details/723739
hbase安装配置:http://blog.csdn.net/hguisu/article/details/7244413
2 . 拷贝hbase-0.90.4.jar和zookeeper-3.3.2.jar到hive/lib下。
注意:如果hive/lib下已经存在这两个文件的其他版本(例如zookeeper-3.3.2.jar),建议删除后使用hbase下的相关版本。
3. 修改hive/conf下hive-site.xml文件,在底部添加如下内容:
- <!--
- <property>
- <name>hive.exec.scratchdir</name>
- <value>/usr/local/hive/tmp</value>
-
- </property>
- -->
-
- <property>
- <name>hive.querylog.location</name>
- <value>/usr/local/hive/logs</value>
- </property>
-
- <property>
- <name>hive.aux.jars.path</name>
- <value>file:///usr/local/hive/lib/hive-hbase-handler-0.8.0.jar,file:///usr/local/hive/lib/hbase-0.90.4.jar,file:///usr/local/hive/lib/zookeeper-3.3.2.jar</value>
-
- </property>
注意:如果hive-site.xml不存在则自行创建,或者把hive-default.xml.template文件改名后使用。
4. 拷贝hbase-0.90.4.jar到所有hadoop节点(包括master)的hadoop/lib下。
5. 拷贝hbase/conf下的hbase-site.xml文件到所有hadoop节点(包括master)的hadoop/conf下。
注意,如果3,4两步跳过的话,运行hive时很可能出现如下错误:
- [html] view plaincopy
- org.apache.hadoop.hbase.ZooKeeperConnectionException: HBase is able to connect to ZooKeeper but the connection closes immediately.
- This could be a sign that the server has too many connections (30 is the default). Consider inspecting your ZK server logs for that error and
- then make sure you are reusing HBaseConfiguration as often as you can. See HTable's javadoc for more information. at org.apache.hadoop.
- hbase.zookeeper.ZooKeeperWatcher.
三、启动Hive
1.单节点启动
#bin/hive -hiveconf hbase.master=master:490001
2 集群启动:
#bin/hive -hiveconf hbase.zookeeper.quorum=node1,node2,node3
如何hive-site.xml文件中没有配置hive.aux.jars.path,则可以按照如下方式启动。
bin/hive --auxpath /usr/local/hive/lib/hive-hbase-handler-
0.8
.
0
.jar, /usr/local/hive/lib/hbase-
0.90
.
5
.jar, /usr/local/hive/lib/zookeeper-
3.3
.
2
.jar -hiveconf hbase.zookeeper.quorum=node1,node2,node3
四、测试:
1.创建hbase识别的数据库:
- CREATE 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" = "xyz");
hbase.table.name 定义在hbase的table名称
hbase.columns.mapping 定义在hbase的列族
2.使用sql导入数据
1) 新建hive的数据表:
CREATE TABLE pokes (foo INT, bar STRING);
2)批量插入数据:
hive> LOAD DATA LOCAL INPATH './examples/files/kv1.txt' OVERWRITE INTO TABLE
3)使用sql导入hbase_table_1:
hive> INSERT OVERWRITE TABLE hbase_table_1 SELECT * FROM pokes WHERE foo=86;
3. 查看数据
hive> select * from hbase_table_1;
这时可以登录Hbase去查看数据了
#bin/hbase shell
hbase(main):001:0> describe 'xyz'
hbase(main):002:0> scan 'xyz'
hbase(main):003:0> put 'xyz','100','cf1:val','www.360buy.com'
这时在Hive中可以看到刚才在Hbase中插入的数据了。
4 hive访问已经存在的hbase
使用CREATE EXTERNAL TABLE:
- CREATE EXTERNAL TABLE hbase_table_2(key int, value string)
- STORED BY 'org.apache.hadoop.hive.hbase.HBaseStorageHandler'
- WITH SERDEPROPERTIES ("hbase.columns.mapping" = "cf1:val")
- TBLPROPERTIES("hbase.table.name" = "some_existing_table");
<value>file:///usr/local/hive-0.8.0-bin/lib/hive_contrib.jar,file:///usr/local/hive-0.8.0-bin/lib/hive-hbase-handler-0.8.0.jar,file:///usr/local/hive-0.8.0-bin/lib/hbase-0.90.4.jar,file:///usr/local/hive-0.8.0-bin/lib/zookeeper-3.4.2.jar
</value>
<value>file:///usr/local/hive/lib/hive-hbase-handler-0.8.0.jar,file:///usr/local/hive/lib/hbase-0.90.4.jar,file:///usr/local/hive/lib/zookeeper-3.3.2.jar</value>
-hiveconf hbase.zookeeper.quorum=master,slave1,slave2
HADOOP_HOME=/usr/local/hadoop-0.20.203.0
CREATE TABLE hbase_table_2(key int, value string)
STORED BY 'org.apache.hadoop.hive.hbase.HBaseStorageHandler'
WITH SERDEPROPERTIES ("hbase.columns.mapping" = ":key,cf1:val")
TBLPROPERTIES ("hbase.table.name" = "abc");
INSERT OVERWRITE TABLE hbase_table_2 SELECT * FROM pokes WHERE foo=86;
LOAD DATA LOCAL INPATH '/usr/local/hive-0.8.0-bin/examples/files/kv1.txt' OVERWRITE INTO TABLE pokes;
分享到:
相关推荐
Hadoop Hive HBase Spark Storm概念解释
该文档保护了目前比较流行的大数据平台的原理过程梳理。Hadoop,Hive,Hbase,Spark,MapReduce,Storm
包含了大量的hadoop hive hbase学习资料
hadoop jar /usr/lib/hbase/hbase-0.90.4-cdh3u3.jar importtsv -Dimporttsv.columns=HBASE_ROW_KEY, catgyname,catgyid1,catgyname1,catgyid2,catgyname2,catgyid3,catgyname3,catgyid4,catgyname4,catgyid5,...
hadoop hive hbase安装过程
hadoop,hbase,hive版本整合兼容性最全,最详细说明【适用于任何版本】,避免下载后才发现不兼容的坑
Hive与hbase的结构,Hive与hbase整合后的结构图 , Hive与hbase整合的原理
Centos+Hadoop+Hive+HBase
被编译的hive-hbase-handler-1.2.1.jar,用于在Hive中创建关联HBase表的jar,解决创建Hive关联HBase时报FAILED: Execution Error, return code 1 from org.apache.hadoop.hive.ql.exec.DDLTask. org.apache.hadoop....
小牛学堂-大数据24期-04-Hadoop Hive Hbase Flume Sqoop-12天适合初学者.txt
jdk1.8.0_131、apache-zookeeper-3.8.0、hadoop-3.3.2、hbase-2.4.12 mysql5.7.38、mysql jdbc驱动mysql-connector-java-8.0.8-dmr-bin.jar、 apache-hive-3.1.3 2.本文软件均安装在自建的目录/export/server/下 ...
hadoop2.2+hbase0.96+hive0.12安装整合详细高可靠文档及经验总结
1、内容概要:Hadoop+Spark+Hive+HBase+Oozie+Kafka+Flume+Flink+Elasticsearch+Redash等大数据集群及组件搭建指南(详细搭建步骤+实践过程问题总结)。 2、适合人群:大数据运维、大数据相关技术及组件初学者。 3、...
Hadoop hbase hive sqoop集群环境安装配置及使用文档
HADOOP+HBASE+HIVE整合工程和文档
spark学习 hadoop hive hbase flink教程 linux 从入门到精通 一个开源、成体系的大数据学习教程。spark学习 hadoop hive hbase flink教程 linux 从入门到精通 一个开源、成体系的大数据学习教程。spark学习 hadoop ...
hadoop+hive+hbase在线装,超级简单