hiveServer2 和 metastore的一点解读。

  刚看了hive官网的文档,对于一些概念结合自己的经验,似乎又多了一些理解,想一想还是记下来的好,一来我是个有些健忘的人,过一段时间即便忘了,循着这个帖子,也能快速把知识点抓起来;二来或许对别人也有些启发。不过首先声明,只是我自己的理解,或许也有错误的地方。。

  1. 先吐个槽,hive的官方文档页面导航就是坨翔,当然,内容还是比较充实的。文档并没有分版本,只是在具体某些内容中对不同版本区别介绍;自己菜单的链接点击后,是一个全新的页面,导航实在太不友好了。

  2. metastore

  hive在部署时,要配置hive-site.xml,这里面的配置很重要的一部分是针对metastore的。什么是metastore?官方解释:"All the metadata for Hive tables and partitions are accessed through the Hive Metastore. ",简单翻一下“对所有hive原数据和分区的访问都要通过Hive Metastore”。

另有一段,附我的翻译:

 1 Remote Metastore Server
 2 In remote metastore setup, all Hive Clients will make a connection to a metastore server which in turn queries the datastore (MySQL in this example) 
 3 for metadata. Metastore server and client communicate using Thrift Protocol. Starting with Hive 0.5.0, you can start a Thrift server by executing 
 4 the following command:
 5 
 6 远程metastore服务:
 7 启动远程metastore后,hive客户端连接metastore服务,从而可以从数据库(本例中位mysql)查询到原数据信息。metastore服务端和客户端通信是通过thrift协议。从hive 0.5.0版本开始,你可以通过执行
 8 以下命令来启动thrift服务。
 9 
10 hive --service metastore

  所以,metastore服务实际上就是一种thrift服务,通过它我们可以获取到hive原数据,并且通过thrift获取原数据的方式,屏蔽了数据库访问需要驱动,url,用户名,密码等等细节。

另外需要说明,以上说的是metastore服务(metastore server)的概念。我们后面还会提到metastore数据库(metastore database),metastore 客户端(metastore client)的概念,但其实metastore服务(metastore server)是理解metastore最重要的概念,所以在这里提前单独提到了。

 

hive中对metastore的配置包含3部分,metastore database,metastore server,metastore client。

其中,metastore database分为Local/Embedded Metastore Database (Derby)和Remote Metastore Database,metastore server也分为Local/Embedded Metastore Server和Remote Metastore Server,本地配置既无太大意义,又要占不少篇幅,我就不讲了,后面的例子都是远程相关配置。

需要注意的几点:

  1)Remote metastore server并不需要额外配置,只要Remote Metastore Database配置好了,"hive --service metastore" 启动metastore会寻找database相关配置。

  2)通常我配置了database,就不配置client了。一般我们的hive都是做服务端的情况较多,不用作为客户端,当然不用客户端的配置了。但是如果仅作为客户端,database配置就不需要了,服务端连元数据库,和客户端没半毛钱直接关系,当然就不需要配置了,但如果作为客户端,而且还要启动hiveServer2服务(该服务也需要访问元数据),那database也是必须配置的。还有一种情况,既是服务端又是客户端,不用说了,都配置上吧。 废话了一大堆,总结一句话,配置多了,一般不会出问题,配少了,就呵呵呵了。。

  3)metastore服务端,客户端的应用场景。spark sql,spark shell终端连接应该就是以客户端的形式连接 hive的metastore服务的。难怪看到官方文档中说准备在3.0版本将metastore独立出去。本来嘛,获取元数据的小活,为什么非得要整合在hive中。

Remote Metastore Database:

Config Param

Config Value

Comment

javax.jdo.option.ConnectionURL

jdbc:mysql://<host name>/<database name>?createDatabaseIfNotExist=true

metadata is stored in a MySQL server

javax.jdo.option.ConnectionDriverName

com.mysql.jdbc.Driver

MySQL JDBC driver class

javax.jdo.option.ConnectionUserName

<user name>

user name for connecting to MySQL server

javax.jdo.option.ConnectionPassword

<password>

password for connecting to MySQL server

 

metastore client Parameters

Config Param

Config Value

Comment

hive.metastore.uris

thrift://<host_name>:<port>

host and port for the Thrift metastore server

hive.metastore.local

false

Metastore is remote.  Note: This is no longer needed as of Hive 0.10.  Setting hive.metastore.uri is sufficient.

hive.metastore.warehouse.dir

<base hdfs path>

Points to default location of non-external Hive tables in HDFS.

 

  3. hiveServer2 

  同样,看一段官方解释:

HiveServer2 (HS2) is a server interface that enables remote clients to execute queries against Hive and retrieve the results (a more detailed intro here).
The current implementation, based on Thrift RPC, is an improved version of HiveServer and supports multi-client concurrency and authentication.

HiveServer2(HS2)是一个服务端接口,使远程客户端可以执行对Hive的查询并返回结果。目前基于Thrift RPC的实现是HiveServer的改进版本,并支持多客户端并发和身份验证

  hiveServer2的启动方式有2种:

1 $HIVE_HOME/bin/hiveserver2
2 或者
3 $HIVE_HOME/bin/hive --service hiveserver2

 启动hiveServer2服务后,就可以使用jdbc,odbc,或者thrift的方式连接。 用java编码jdbc或则beeline连接使用jdbc的方式,据说hue是用thrift的方式连接的hive服务。

 

我的一点疑问,hiveServer2和metastore都会访问元数据,他们的访问方式是怎样的?是相同的,还是相似的。元数据的访问有没有可能仅需要一个服务?我现在访问hive服务需要启动hiveServer2,访问sparksql需要启动metastore,如果两个都会启动metastore,我觉得有些奇怪。

 

posted @ 2018-05-12 20:48  aj117  阅读(22306)  评论(3编辑  收藏  举报