欢迎投稿

今日深度:

hive安装,

hive安装,


http://blog.csdn.net/hguisu/article/details/7282050

hadoop、hbase的安装见前面的文章
下面是hive的安装
1、下载
http://mirror.bit.edu.cn/apache/hive/stable/

Hadoop Hive与Hbase整合

一 、简介

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下的相关版本。

2. 修改hive/conf下hive-site.xml文件,在底部添加如下内容:

  1. <!--
  2. <property>
  3. <name>hive.exec.scratchdir</name>
  4. <value>/usr/local/hive/tmp</value>
  5. </property>
  6. -->
  7. <property>
  8. <name>hive.querylog.location</name>
  9. <value>/usr/local/hive/logs</value>
  10. </property>
  11. <property>
  12. <name>hive.aux.jars.path</name>
  13. <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>
  14. </property>

注意:如果hive-site.xml不存在则自行创建,或者把hive-default.xml.template文件改名后使用。

3. 拷贝hbase-0.90.4.jar到所有hadoop节点(包括master)的hadoop/lib下。

4. 拷贝hbase/conf下的hbase-site.xml文件到所有hadoop节点(包括master)的hadoop/conf下。

注意,如果3,4两步跳过的话,运行hive时很可能出现如下错误:

  1. [html]viewplaincopy
  2. org.apache.hadoop.hbase.ZooKeeperConnectionException:HBaseisabletoconnecttoZooKeeperbuttheconnectionclosesimmediately.
  3. Thiscouldbeasignthattheserverhastoomanyconnections(30isthedefault).ConsiderinspectingyourZKserverlogsforthaterrorand
  4. thenmakesureyouarereusingHBaseConfigurationasoftenasyoucan.SeeHTable'sjavadocformoreinformation.atorg.apache.hadoop.
  5. hbase.zookeeper.ZooKeeperWatcher.

    以下是我的hive-site.xml文件内容:
    </property>


    <!--
    <property>
    <name>hive.exec.scratchdir</name>
    <value>/home/cheng/hive-0.8.1/tmp</value>

    </property>
    -->

    <property>
    <name>hive.querylog.location</name>
    <value>/home/cheng/hive-0.8.1/logs</value>
    </property>

    <property>
    <name>hive.aux.jars.path</name>
    <value>file:///home/cheng/hive-0.8.1/lib/hive-hbase-handler-0.8.1.jar,file:///home/cheng/hive-0.8.1/lib/hbase-0.89.0-SNAPSHOT.jar,file:///home/cheng/hive-0.8.1/lib/zookeeper-3.4.3.jar</value>

    </property>


    </configuration>
    我没有找到hbase-0.90.4.jar这个文件,就使用hive自带的
    然后将hive打包scp到相应的各个机器上。

三、启动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识别的数据库:

  1. CREATETABLEhbase_table_1(keyint,valuestring)
  2. STOREDBY'org.apache.hadoop.hive.hbase.HBaseStorageHandler'
  3. WITHSERDEPROPERTIES("hbase.columns.mapping"=":key,cf1:val")
  4. 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:

  1. CREATEEXTERNALTABLEhbase_table_2(keyint,valuestring)
  2. STOREDBY'org.apache.hadoop.hive.hbase.HBaseStorageHandler'
  3. WITHSERDEPROPERTIES("hbase.columns.mapping"="cf1:val")
  4. TBLPROPERTIES("hbase.table.name"="some_existing_table");
内容参考:http://wiki.apache.org/hadoop/Hive/HBaseIntegration

创建hbase识别的数据库总是报错误:
hive> 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");
FAILED: Error in metadata: java.lang.IllegalArgumentException: Not a host:port pair: 锟?
还没有解决

解决:
其实还是上面的安装步骤有问题导致了一直报这个错误,需要注意的是这一步:

拷贝hbase-0.90.4.jar和zookeeper-3.3.2.jar到hive/lib下。
其中hbase-0.92.1.jar所在的路径是/home/cheng/hbase-0.92.1/hbase-0.92.1.jar(我的hbase版本高),原来弄错了以为是在hbase的lib路径下那。然后将该jar包拷贝到hive/lib以及hadoop/lib下就可以了
cheng@ip83 hive-0.8.1]$ ./bin/hive --auxpath file:///home/cheng/hive-0.8.1/lib/hive-hbase-handler-0.8.1.jar,file:///home/cheng/hive-0.8.1/lib/hbase-0.92.1.jar,file:///home/cheng/hive-0.8.1/lib/zookeeper-3.4.3.jar -hiveconf hbase.zookeeper.quorum=ip81,ip82,ip83
WARNING: org.apache.hadoop.metrics.jvm.EventCounter is deprecated. Please use org.apache.hadoop.log.metrics.EventCounter in all the log4j.properties files.
Logging initialized using configuration in jar:file:/home/cheng/hive-0.8.1/lib/hive-common-0.8.1.jar!/hive-log4j.properties
Hive history file=/home/cheng/hive-0.8.1/logs/hive_job_log_cheng_201205151131_1369166340.txt
hive> 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");
OK
Time taken: 9.152 seconds
hive>
其中

WARNING: org.apache.hadoop.metrics.jvm.EventCounter is deprecated. Please use org.apache.hadoop.log.metrics.EventCounter in all the log4j.properties files.
好像是个bug可以忽略,到此hadoop+hbase+hive集群安装完成

www.htsjk.Com true http://www.htsjk.com/hive/41307.html NewsArticle hive安装, http://blog.csdn.net/hguisu/article/details/7282050 hadoop、hbase的安装见前面的文章 下面是hive的安装 1、下载 http://mirror.bit.edu.cn/apache/hive/stable/ Hadoop Hive与Hbase整合 一 、简介 Hive是基于...
相关文章
    暂无相关文章
评论暂时关闭