hive2.1.0初探以及其中踩的坑

本文详细介绍了Hive 2.1.0版本的部署步骤及过程中可能遇到的问题解决方案,并对比了与Hive 1.2版本的区别,重点突出了新增的HBase支持、HPL/SQL工具以及LLAP服务等新特性。

转载请注明出处:http://blog.youkuaiyun.com/gamer_gyt
博主微博:http://weibo.com/234654758
Github:https://github.com/thinkgamer


前言

        hive 2.x版本出来已经有一段时间了,目前的2.x中的稳定版本为2.1.0
        github地址:https://github.com/apache/hive/tree/master
        官方下载地址为:https://mirrors.tuna.tsinghua.edu.cn/apache/hive/
        工作之余,我们就来看看hive2.1.0这个版本相对于1.2来说的change


部署

之前的一篇hive1.2的mysql部署文章:
          http://blog.youkuaiyun.com/gamer_gyt/article/details/52032579

hive2.1.0相对1.2来讲部署上并没有什么变化,但就算是温习吧,我们依旧走一遍这个过程,看看有哪些坑等着我们去踩。

1:下载文件

2:解压至指定目录

我这里hive的存放目录是/opt/bigdata/hive,并重命名为hive

tar -zxvf /home/thinkgamer/下载/apache-hive-2.1.0-bin.tar.gz -C /opt/bigdata/
mv apache-hive-2.1.0-bin/ hive

3:Mysql创建hive21用户

创建hive21用户,赋予权限,清除缓存

CREATE USER 'hive21' IDENTIFIED BY 'hive21';
grant all privileges on *.* to 'hive21' with grant option;
flush privileges;

4:拷贝msyql jar包到hive/lib

cp /path/to/mysql-connector-java-5.1.38-bin.jar hive/lib

5:修改配置文件

(1):javax.jdo.option.ConnectionURL
<name>javax.jdo.option.ConnectionURL</name>
    <value>jdbc:mysql://localhost:3306/hive21?createDatabaseIfNotExist=true&amp;useUnicode=true&amp;characterEncoding=UTF-8</value>

(2):javax.jdo.option.ConnectionDriverName
<name>javax.jdo.option.ConnectionDriverName</name>
<value>com.mysql.jdbc.Driver</value>
(3):javax.jdo.option.ConnectionUserName
<name>javax.jdo.option.ConnectionUserName</name>  
<value>hive21</value>  
(4):javax.jdo.option.ConnectionPassword
<name>javax.jdo.option.ConnectionPassword</name>
<value>hive21</value>

6:启动/测试

bin/hive

hive> show databases;
OK
default
Time taken: 1.123 seconds, Fetched: 1 row(s)
hive> create table table_name (  
    >   id                int,  
    >   dtDontQuery       string,  
    >   name              string  
    > );  
OK
Time taken: 0.983 seconds
hive> show tables;
OK
table_name
Time taken: 0.094 seconds, Fetched: 1 row(s)

这个时候进入mysql数据库有一个hive21的数据库

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| hive               |
| hive21             |
| mysql              |
| performance_schema |
+--------------------+

7:踩过的坑

####(1):没有初始化hive元数据库
报错如下:

Caused by: MetaException(message:Hive metastore database is not initialized. Please use schematool (e.g. ./schematool -initSchema -dbType ...) to create the schema.  
If needed, don't forget to include the option to auto-create the underlying database in your JDBC connection string (e.g. ?createDatabaseIfNotExist=true for mysql))  

解决办法:

bin/schematool -initSchema -dbType mysql --verbose 

此问题解决时在网上查阅资料有人说这里要初始化derby数据库,个人认为这是不正确的,因为我们已经配置使用了mysql作为元数据库

####(2):未配置日志和缓存目录
报错如下:

Logging initialized using configuration in file:/opt/bigdata/hive/conf/hive-log4j2.properties Async: true
Exception in thread "main" java.lang.IllegalArgumentException: java.net.URISyntaxException: Relative path in absolute URI: ${system:java.io.tmpdir%7D/$%7Bsystem:user.name%7D
	at org.apache.hadoop.fs.Path.initialize(Path.java:205)
	at org.apache.hadoop.fs.Path.<init>(Path.java:171)
	at org.apache.hadoop.hive.ql.session.SessionState.createSessionDirs(SessionState.java:631)
	at org.apache.hadoop.hive.ql.session.SessionState.start(SessionState.java:550)
	at org.apache.hadoop.hive.ql.session.SessionState.beginStart(SessionState.java:518)
	at org.apache.hadoop.hive.cli.CliDriver.run(CliDriver.java:705)
	at org.apache.hadoop.hive.cli.CliDriver.main(CliDriver.java:641)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.apache.hadoop.util.RunJar.run(RunJar.java:221)
	at org.apache.hadoop.util.RunJar.main(RunJar.java:136)
Caused by: java.net.URISyntaxException: Relative path in absolute URI: ${system:java.io.tmpdir%7D/$%7Bsystem:user.name%7D
	at java.net.URI.checkPath(URI.java:1823)
	at java.net.URI.<init>(URI.java:745)
	at org.apache.hadoop.fs.Path.initialize(Path.java:202)
	... 12 more

解决办法:

修改 hive-site.xml 替换${system:java.io.tmpdir} 和 ${system:user.name}为/opt/bigdata/hive/tmp


hive2.1 和hive1.2的简单比较

hive1.2

[master@master1 hive]$ bin/hive --service help  
Usage ./hive <parameters> --service serviceName <service parameters>  
Service List: beeline cli help hiveburninclient hiveserver2 hiveserver hwi jar lineage metastore metatool orcfiledump rcfilecat schemaTool version   
Parameters parsed:  
  --auxpath : Auxillary jars   
  --config : Hive configuration directory  
  --service : Starts specific service/component. cli is default  
Parameters used:  
  HADOOP_HOME or HADOOP_PREFIX : Hadoop install directory  
  HIVE_OPT : Hive options  
For help on a particular service:  
  ./hive --service serviceName --help  
Debug help:  ./hive --debug --help  

hive2.1

root@thinkgamer-pc:/opt/bigdata/hive# bin/hive --service help
Usage ./hive <parameters> --service serviceName <service parameters>
Service List: beeline cleardanglingscratchdir cli hbaseimport hbaseschematool help hiveburninclient hiveserver2 hplsql hwi jar lineage llapdump llap llapstatus metastore metatool orcfiledump rcfilecat schemaTool version 
Parameters parsed:
  --auxpath : Auxillary jars 
  --config : Hive configuration directory
  --service : Starts specific service/component. cli is default
Parameters used:
  HADOOP_HOME or HADOOP_PREFIX : Hadoop install directory
  HIVE_OPT : Hive options
For help on a particular service:
  ./hive --service serviceName --help
Debug help:  ./hive --debug --help

我们可以看到在hive2.1中增加了对hbase的支持,同时还增加了hplsql等等,这些都是hive2.1的新特性,这里介绍几个常用的

  • beeline:和hive1.2中beeline使用方法应该是一样的,至于性能方面的提升肯定是有的,beeline的使用,参考
    http://blog.youkuaiyun.com/gamer_gyt/article/details/52062460

  • cleardanglingscratchdir:scratch directory(清楚缓存)
    使用方法: bin/hive --service cleardanglingscratchdir

  • hbaseimport/hbaseschematool:与Hbase进行交互

  • hiveserver2:提供一个JDBC接口,供外部程序操作hive

  • hplsql:一个工具,实现sql在Apache hive,sparkSql,以及其他基于hadoop的sql,Nosql和关系数据库的使用
    官方解释:

HPL/SQL (previously known as PL/HQL) is an open source tool (Apache License 2.0) that implements procedural SQL language for Apache Hive, SparkSQL as well as any other SQL-on-Hadoop implementations, NoSQL and RDBMS.

HPL/SQL language is compatible to a large extent with Oracle PL/SQL, ANSI/ISO SQL/PSM (IBM DB2, MySQL, Teradata i.e), PostgreSQL PL/pgSQL (Netezza), Transact-SQL (Microsoft SQL Server and Sybase) that allows you leveraging existing SQL/DWH skills and familiar approach to implement data warehouse solutions on Hadoop. It also facilitates migration of existing business logic to Hadoop.

HPL/SQL is an efficient way to implement ETL processes in Hadoop.
  • LLAP:也是hive2.1引入的新特性,大概就是提升hive2.1的执行时间,具体可参考:
    http://zh.hortonworks.com/blog/llap-enables-sub-second-sql-hadoop/

下面附一张从网上看到的图片:
这里写图片描述

【技术服务】,详情点击查看: https://mp.weixin.qq.com/s/PtX9ukKRBmazAWARprGIAg

扫一扫 关注微信公众号!号主 专注于搜索和推荐系统,尝试使用算法去更好的服务于用户,包括但不局限于机器学习,深度学习,强化学习,自然语言理解,知识图谱,还不定时分享技术,资料,思考等文章!

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值