1. 程式人生 > >hiveServer2 和 metastore的一點解讀。

hiveServer2 和 metastore的一點解讀。

鏈接 等等 中間 tex ret lin 目前 vax using

  剛看了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”。

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

另有一段,附我的翻譯:

Remote Metastore Server
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) 
for metadata. Metastore server and client communicate using Thrift Protocol. Starting with Hive 0.5.0, you can start a Thrift server by executing 
the following command:

遠程metastore服務:
啟動遠程metastore後,hive客戶端連接metastore服務,從而可以從數據庫(本例中位mysql)查詢到原數據信息。metastore服務端和客戶端通信是通過thrift協議。從hive 0.5.0版本開始,你可以通過執行
以下命令來啟動thrift服務。

hive --service metastore

  所以,metastore服務實際上就是一種thrift服務,通過它我們可以獲取到hive原數據,並且通過thrift獲取原數據的方式,屏蔽了數據庫訪問需要驅動,url,用戶名,密碼等等細節。

另外需要說明,以上說的是metastore服務端的概念。如果你的hive作為一個metastore客戶端去連接服務端,是需要額外的客戶端配置參數的,如下:

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編碼jdvc或則beeline連接使用jdvc的方式,據說hue是用thrift的方式連接的hive服務。

我的一點疑問,hiveServer2和metastore都會訪問元數據,他們的訪問方式是怎樣的?是相同的,還是相似的。元數據的訪問有沒有可能僅需要一個服務?我現在啟動hiveServer2提供hive服務,啟動metastore服務供sparksql訪問元數據,感覺有些麻煩。

本文中間一部分有些亂,日後在修改吧,休息會先。。。

hiveServer2 和 metastore的一點解讀。