hive的启动需要使用到zookeeper, 所以, 要么自己搭建zookeeper, 要么跟其它东西一起使用, 我这里做的是跟hbase一起使用的zookeeper, 因为hbase自带zookeeper, hbase启动就会启动zookeeper, 而hive默认会连接本机的2181端口, 所以我这里选择在slaver3上使用hive.





集群的搭建以及机器的分配见hadoop搭建: http://phey.cc/multinode_hadoop20.html

以及hbase集群搭建http://phey.cc/Install_hbase_cluster.html





解压hive包后拷贝环境变量模板到指定文件

[cc@slaver3 ~]$ cp hive-0.12.0-cdh5.0.1/conf/hive-env.sh.template hive-0.12.0-cdh5.0.1/conf/hive-env.sh

[cc@slaver3 ~]$ ▊









编辑环境变量, 一个是hadoop的安装目录,一个是hbase的jar位置,如果hbase和hive的jar版本不对会报错

[cc@slaver3 ~]$ vim hive-0.12.0-cdh5.0.1/conf/hive-env.sh

export HADOOP_HOME=/home/cc/hadoop-2.3.0-cdh5.0.0

export HIVE_AUX_JARS_PATH=/home/cc/hbase-0.96.1.1-cdh5.0.1/lib

[cc@slaver3 ~]$ ▊









启动hive,指定hbase的RPC端口

[cc@slaver3 hive-0.12.0-cdh5.0.1]$ bin/hive -hiveconf hbase.master=master1:60000

14/08/21 21:34:07 INFO Configuration.deprecation: mapred.input.dir.recursive is deprecated. Instead, use mapreduce.input.fileinputformat.input.dir.recursive

14/08/21 21:34:07 INFO Configuration.deprecation: mapred.max.split.size is deprecated. Instead, use mapreduce.input.fileinputformat.split.maxsize

14/08/21 21:34:07 INFO Configuration.deprecation: mapred.min.split.size is deprecated. Instead, use mapreduce.input.fileinputformat.split.minsize

14/08/21 21:34:07 INFO Configuration.deprecation: mapred.min.split.size.per.rack is deprecated. Instead, use mapreduce.input.fileinputformat.split.minsize.per.rack

14/08/21 21:34:07 INFO Configuration.deprecation: mapred.min.split.size.per.node is deprecated. Instead, use mapreduce.input.fileinputformat.split.minsize.per.node

14/08/21 21:34:07 INFO Configuration.deprecation: mapred.reduce.tasks is deprecated. Instead, use mapreduce.job.reduces

14/08/21 21:34:07 INFO Configuration.deprecation: mapred.reduce.tasks.speculative.execution is deprecated. Instead, use mapreduce.reduce.speculative





Logging initialized using configuration in jar:file:/home/cc/hive-0.12.0-cdh5.0.1/lib/hive-common-0.12.0-cdh5.0.1.jar!/hive-log4j.properties

SLF4J: Class path contains multiple SLF4J bindings.

SLF4J: Found binding in [jar:file:/home/cc/hadoop-2.3.0-cdh5.0.0/share/hadoop/common/lib/slf4j-log4j12-1.7.5.jar!/org/slf4j/impl/StaticLoggerBinder.class]

SLF4J: Found binding in [jar:file:/home/cc/hive-0.12.0-cdh5.0.1/lib/slf4j-log4j12-1.7.5.jar!/org/slf4j/impl/StaticLoggerBinder.class]

SLF4J: Found binding in [jar:file:/home/cc/hbase-0.96.1.1-cdh5.0.1/lib/slf4j-log4j12-1.7.5.jar!/org/slf4j/impl/StaticLoggerBinder.class]

SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.

SLF4J: Actual binding is of type [org.slf4j.impl.Log4jLoggerFactory]

hive> ▊









在hive中建表。在hive新建一个名为cctabl的表,这个表映射到hbase的表名是cc,cctable表里面的int类型的key对应了cc表里面的row key,cctable里面类型是string的value对应了cc表里面的cf:val

hive> CREATE TABLE cctable (key int, value string) STORED BY 'org.apache.hadoop.hive.hbase.HBaseStorageHandler' WITH SERDEPROPERTIES ("hbase.columns.mapping" = ":key,cf:val") TBLPROPERTIES ("hbase.table.name" = "cc");

OK

Time taken: 9.302 seconds

hive> ▊









在hbase中可以看到结果, 创建了一个表

hbase(main):011:0> list

TABLE                                                                                                                                                                 

cc                                                                                                                                                                    

1 row(s) in 0.0250 seconds





=> ["cc"]

hbase(main):012:0> describe 'cc'

DESCRIPTION                                                                                                 ENABLED                                                   

 'cc', {NAME => 'cf', DATA_BLOCK_ENCODING => 'NONE', BLOOMFILTER => 'ROW', REPLICATION_SCOPE => '0', VERSIO true                                                      

 NS => '1', COMPRESSION => 'NONE', MIN_VERSIONS => '0', TTL => '2147483647', KEEP_DELETED_CELLS => 'false',                                                           

  BLOCKSIZE => '65536', IN_MEMORY => 'false', BLOCKCACHE => 'true'}                                                                                                   

1 row(s) in 0.0390 seconds





hbase(main):013:0> ▊









如果不希望hive去创建表而是使用hbase已经有的表, 那么创建表的时候加上external参数就可以了, 例如

hive> CREATE EXTERNAL TABLE cctable (key int, value string) STORED BY 'org.apache.hadoop.hive.hbase.HBaseStorageHandler' WITH SERDEPROPERTIES ("hbase.columns.mapping" = ":key,cf:val") TBLPROPERTIES ("hbase.table.name" = "cc");

OK

Time taken: 9.302 seconds

hive> ▊









由于有那个映射关系,所以往hbase里面插入数据可以在hive里面查询,不过hive不支持类似于mysql的insert语句,所以方便的也只能往hbase里面插入数据





向hbase里面插入数据

hbase(main):013:0> put 'cc', '1', 'cf:val', 'hello cc!'

0 row(s) in 0.0120 seconds





hbase(main):014:0> ▊









在hive里面查询

hive> select * from cctable;

OK

1       hello cc!

Time taken: 30.838 seconds, Fetched: 1 row(s)

hive> ▊









虽然hbase不支持count方法去计算行数,但是hive可以,不过这个会被转换成mapreduce过程,去执行

hive> select count(*) from cctable;

Total MapReduce jobs = 1

Launching Job 1 out of 1

Number of reduce tasks determined at compile time: 1

In order to change the average load for a reducer (in bytes):

  set hive.exec.reducers.bytes.per.reducer=<number>

In order to limit the maximum number of reducers:

  set hive.exec.reducers.max=<number>

In order to set a constant number of reducers:

  set mapred.reduce.tasks=<number>

Starting Job = job_1408532552242_0005, Tracking URL = http://master1:8088/proxy/application_1408532552242_0005/

Kill Command = /home/cc/hadoop-2.3.0-cdh5.0.0/bin/hadoop job  -kill job_1408532552242_0005

Hadoop job information for Stage-1: number of mappers: 1; number of reducers: 1

2014-08-22 10:15:00,861 Stage-1 map = 0%,  reduce = 0%

2014-08-22 10:15:14,479 Stage-1 map = 100%,  reduce = 0%, Cumulative CPU 2.73 sec

2014-08-22 10:15:15,525 Stage-1 map = 100%,  reduce = 0%, Cumulative CPU 2.73 sec

2014-08-22 10:15:16,572 Stage-1 map = 100%,  reduce = 0%, Cumulative CPU 2.73 sec

2014-08-22 10:15:17,617 Stage-1 map = 100%,  reduce = 0%, Cumulative CPU 2.73 sec

2014-08-22 10:15:18,662 Stage-1 map = 100%,  reduce = 0%, Cumulative CPU 2.73 sec

2014-08-22 10:15:19,707 Stage-1 map = 100%,  reduce = 0%, Cumulative CPU 2.73 sec

2014-08-22 10:15:20,753 Stage-1 map = 100%,  reduce = 0%, Cumulative CPU 2.73 sec

2014-08-22 10:15:21,798 Stage-1 map = 100%,  reduce = 0%, Cumulative CPU 2.73 sec

2014-08-22 10:15:22,842 Stage-1 map = 100%,  reduce = 0%, Cumulative CPU 2.73 sec

2014-08-22 10:15:23,889 Stage-1 map = 100%,  reduce = 0%, Cumulative CPU 2.73 sec

2014-08-22 10:15:24,937 Stage-1 map = 100%,  reduce = 0%, Cumulative CPU 2.73 sec

2014-08-22 10:15:25,991 Stage-1 map = 100%,  reduce = 0%, Cumulative CPU 2.73 sec

2014-08-22 10:15:27,040 Stage-1 map = 100%,  reduce = 0%, Cumulative CPU 2.73 sec

2014-08-22 10:15:28,094 Stage-1 map = 100%,  reduce = 100%, Cumulative CPU 4.89 sec

2014-08-22 10:15:29,143 Stage-1 map = 100%,  reduce = 100%, Cumulative CPU 4.89 sec

MapReduce Total cumulative CPU time: 4 seconds 890 msec

Ended Job = job_1408532552242_0005

MapReduce Jobs Launched: 

Job 0: Map: 1  Reduce: 1   Cumulative CPU: 4.89 sec   HDFS Read: 236 HDFS Write: 2 SUCCESS

Total MapReduce CPU Time Spent: 4 seconds 890 msec

OK

1

Time taken: 77.571 seconds, Fetched: 1 row(s)

hive> ▊

Hive与Hbase结合使用的更多相关文章

  1. 使用Sqoop从MySQL导入数据到Hive和HBase 及近期感悟

    使用Sqoop从MySQL导入数据到Hive和HBase 及近期感悟 Sqoop 大数据 Hive HBase ETL 使用Sqoop从MySQL导入数据到Hive和HBase 及近期感悟 基础环境 ...

  2. hive与hbase整合过程

    实现目标 Hive可以实时查询Hbase中的数据. hive中的表插入数据会同步更新到hbase对应的表中. 可以将hbase中不同的表中的列通过 left 或 inner join 方式映射到hiv ...

  3. Hive集成HBase;安装pig

    Hive集成HBase 配置 将hive的lib/中的HBase.jar包用实际安装的Hbase的jar包替换掉 cd /opt/hive/lib/ ls hbase-0.94.2*  rm -rf ...

  4. Hive 实现HBase 数据批量插入

    HBase 数据的插入可以使用Java API 来写Java 程序逐条倒入,但是不是很方便.利用Hive自带的一个Jar包,可以建立Hive和HBase的映射关系 利用Hive 的insert可以将批 ...

  5. Hive Over HBase

    1. 在hbase上建测试表 hbase(main)::> create 'test_hive_over_hbase','f' row(s) in 2.5810 seconds hbase(ma ...

  6. Hive(五):hive与hbase整合

    配置 hive 与 hbase 整合的目的是利用 HQL 语法实现对 hbase 数据库的增删改查操作,基本原理就是利用两者本身对外的API接口互相进行通信,两者通信主要是依靠hive_hbase-h ...

  7. hive到hbase的使用

    一.简单介绍 hive的元数据保存在metastore里面,真实的数据一般位于hdfs中,可以通过hql来对数据进行分析.hbase中的数据也是存放在hdfs上的,可不可以使用hive来分析hbase ...

  8. Hive与HBase区别

    对于刚接触大数据的用户来说,要想区分Hive与HBase是有一定难度的.本文将尝试从其各自的定义.特点.限制.应用场景等角度来进行分析,以作抛砖引玉之用. ====Hive是什么?Apache Hiv ...

  9. hive和hbase整合的原因和原理

    为什么要进行hive和hbase的整合? hive是高延迟.结构化和面向分析的: hbase是低延迟.非结构化和面向编程的. Hive集成Hbase就是为了使用hbase的一些特性.或者说是中和它们的 ...

  10. Hive over HBase和Hive over HDFS性能比较分析

    http://superlxw1234.iteye.com/blog/2008274 环境配置: hadoop-2.0.0-cdh4.3.0 (4 nodes, 24G mem/node) hbase ...

随机推荐

  1. 20145229吴姗珊 《Java程序设计》第9周总结

    20145229吴姗珊 <Java程序设计>第9周总结 教材学习内容总结 第十六章 整合数据库 JDBC入门 数据库本身是个独立运行的应用程序 撰写应用程序是利用通信协议对数据库进行指令交 ...

  2. 51nod 1681

    题目 神犇题解 这题挺神的..思路很巧妙 首先想到DFS序(毕竟是子树问题),这道题可以转化成:我们对于每一个节点的子树区间去看,两棵树同一节点的这个子树区间有多少个相同元素,设个数为x,那么这个点的 ...

  3. codeforces 707D:Persistent Bookcase

    Description Recently in school Alina has learned what are the persistent data structures: they are d ...

  4. 各种IoC框架下实现AOP

    .Net AOP(五) 各种IoC框架下实现AOP 利用AOP可以对业务逻辑的各个部分进行隔离,从而使得业务逻辑各部分之间的耦合度降低,提高程序的可重用性,同时提高了开发的效率 主要功能 日志记录,性 ...

  5. The Quantum L3 router and floating IPs

    This post shows how the Quantum L3 Agent uses the Linux IP stack to implement the Quantum L3 Routing ...

  6. 如何设置minSdkVersion和targetSdkVersion

    转http://www.07net01.com/2015/07/878098.html minSdkversion和targetSdkVersion相信很多人都不太理解,我在网上也看了许多关于这两者区 ...

  7. 【python】关于函数递归使用 return 后,收到数据为 None。

    在写一个辗转相除求最小公因数的程序的时候,突然发现自己不管怎么写(除了两数恰巧可以整除),return 返回的值恒为 none. 代码为此: def gcd(a,b): if a%b==0: retu ...

  8. ES doc_values介绍——本质是field value的列存储,做聚合分析用,ES默认开启,会占用存储空间(列存储压缩技巧,除公共除数或者同时减去最小数,字符串压缩的话,直接去重后用数字ID压缩)

    doc_values Doc values are the on-disk data structure, built at document index time, which makes this ...

  9. 【二叉树的递归】02二叉树的最大深度【Maximum Depth of Binary Tree】

    ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 给定一个二叉树,找出他的最小的深度 ...

  10. freeMarker(七)——程序开发指南之数据模型

    学习笔记,选自freeMarker中文文档,译自 Email: ddekany at users.sourceforge.net 1.基本内容 在入门章节中, 我们已经知道如何使用基本的Java类(M ...