hiveServer2 和 metastore的一点解读。
剛看了hive官網(wǎng)的文檔,對(duì)于一些概念結(jié)合自己的經(jīng)驗(yàn),似乎又多了一些理解,想一想還是記下來的好,一來我是個(gè)有些健忘的人,過一段時(shí)間即便忘了,循著這個(gè)帖子,也能快速把知識(shí)點(diǎn)抓起來;二來或許對(duì)別人也有些啟發(fā)。不過首先聲明,只是我自己的理解,或許也有錯(cuò)誤的地方。。
1. 先吐個(gè)槽,hive的官方文檔頁面導(dǎo)航就是坨翔,當(dāng)然,內(nèi)容還是比較充實(shí)的。文檔并沒有分版本,只是在具體某些內(nèi)容中對(duì)不同版本區(qū)別介紹;自己菜單的鏈接點(diǎn)擊后,是一個(gè)全新的頁面,導(dǎo)航實(shí)在太不友好了。
2. metastore
hive在部署時(shí),要配置hive-site.xml,這里面的配置很重要的一部分是針對(duì)metastore的。什么是metastore?官方解釋:"All the metadata for Hive tables and partitions are accessed through the Hive Metastore. ",簡單翻一下“對(duì)所有hive原數(shù)據(jù)和分區(qū)的訪問都要通過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 遠(yuǎn)程metastore服務(wù): 7 啟動(dòng)遠(yuǎn)程metastore后,hive客戶端連接metastore服務(wù),從而可以從數(shù)據(jù)庫(本例中位mysql)查詢到原數(shù)據(jù)信息。metastore服務(wù)端和客戶端通信是通過thrift協(xié)議。從hive 0.5.0版本開始,你可以通過執(zhí)行 8 以下命令來啟動(dòng)thrift服務(wù)。 9 10 hive --service metastore所以,metastore服務(wù)實(shí)際上就是一種thrift服務(wù),通過它我們可以獲取到hive原數(shù)據(jù),并且通過thrift獲取原數(shù)據(jù)的方式,屏蔽了數(shù)據(jù)庫訪問需要驅(qū)動(dòng),url,用戶名,密碼等等細(xì)節(jié)。
另外需要說明,以上說的是metastore服務(wù)(metastore server)的概念。我們后面還會(huì)提到metastore數(shù)據(jù)庫(metastore database),metastore 客戶端(metastore client)的概念,但其實(shí)metastore服務(wù)(metastore server)是理解metastore最重要的概念,所以在這里提前單獨(dú)提到了。
?
hive中對(duì)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,本地配置既無太大意義,又要占不少篇幅,我就不講了,后面的例子都是遠(yuǎn)程相關(guān)配置。
需要注意的幾點(diǎn):
1)Remote?metastore server并不需要額外配置,只要Remote Metastore Database配置好了,"hive --service metastore"?啟動(dòng)metastore會(huì)尋找database相關(guān)配置。
2)通常我配置了database,就不配置client了。一般我們的hive都是做服務(wù)端的情況較多,不用作為客戶端,當(dāng)然不用客戶端的配置了。但是如果僅作為客戶端,database配置就不需要了,服務(wù)端連元數(shù)據(jù)庫,和客戶端沒半毛錢直接關(guān)系,當(dāng)然就不需要配置了,但如果作為客戶端,而且還要啟動(dòng)hiveServer2服務(wù)(該服務(wù)也需要訪問元數(shù)據(jù)),那database也是必須配置的。還有一種情況,既是服務(wù)端又是客戶端,不用說了,都配置上吧。 廢話了一大堆,總結(jié)一句話,配置多了,一般不會(huì)出問題,配少了,就呵呵呵了。。
3)metastore服務(wù)端,客戶端的應(yīng)用場(chǎng)景。spark sql,spark shell終端連接應(yīng)該就是以客戶端的形式連接 hive的metastore服務(wù)的。難怪看到官方文檔中說準(zhǔn)備在3.0版本將metastore獨(dú)立出去。本來嘛,獲取元數(shù)據(jù)的小活,為什么非得要整合在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)是一個(gè)服務(wù)端接口,使遠(yuǎn)程客戶端可以執(zhí)行對(duì)Hive的查詢并返回結(jié)果。目前基于Thrift RPC的實(shí)現(xiàn)是HiveServer的改進(jìn)版本,并支持多客戶端并發(fā)和身份驗(yàn)證
hiveServer2的啟動(dòng)方式有2種:
1 $HIVE_HOME/bin/hiveserver2 2 或者 3 $HIVE_HOME/bin/hive --service hiveserver2?啟動(dòng)hiveServer2服務(wù)后,就可以使用jdbc,odbc,或者thrift的方式連接。 用java編碼jdbc或則beeline連接使用jdbc的方式,據(jù)說hue是用thrift的方式連接的hive服務(wù)。
?
我的一點(diǎn)疑問,hiveServer2和metastore都會(huì)訪問元數(shù)據(jù),他們的訪問方式是怎樣的?是相同的,還是相似的。元數(shù)據(jù)的訪問有沒有可能僅需要一個(gè)服務(wù)?我現(xiàn)在訪問hive服務(wù)需要啟動(dòng)hiveServer2,訪問sparksql需要啟動(dòng)metastore,如果兩個(gè)都會(huì)啟動(dòng)metastore,我覺得有些奇怪。
?
轉(zhuǎn)載于:https://www.cnblogs.com/tibit/p/9029905.html
總結(jié)
以上是生活随笔為你收集整理的hiveServer2 和 metastore的一点解读。的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 【IdentityServer4文档】-
- 下一篇: 简单线性回归预测实现