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:
| 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
| 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,我覺得有些奇怪。
?
轉載于:https://www.cnblogs.com/tibit/p/9029905.html
總結
以上是生活随笔為你收集整理的hiveServer2 和 metastore的一点解读。的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 【IdentityServer4文档】-
- 下一篇: 简单线性回归预测实现