Hive基礎(4)---Hive的內置服務

 

目錄(?)[+]java

 

一:Hive的幾種內置服務

             執行bin/hive --service help  以下:      python

 

[html]  view plain  copy
 
 在CODE上查看代碼片派生到個人代碼片
  1. [master@master1 hive]$ bin/hive --service help  
  2. ls: 沒法訪問/opt/spark/lib/spark-assembly-*.jar: 沒有那個文件或目錄  
  3. Usage ./hive <parameters> --service serviceName <service parameters>  
  4. Service List: beeline cli help hiveburninclient hiveserver2 hiveserver hwi jar lineage metastore metatool orcfiledump rcfilecat schemaTool version   
  5. Parameters parsed:  
  6.   --auxpath : Auxillary jars   
  7.   --config : Hive configuration directory  
  8.   --service : Starts specific service/component. cli is default  
  9. Parameters used:  
  10.   HADOOP_HOME or HADOOP_PREFIX : Hadoop install directory  
  11.   HIVE_OPT : Hive options  
  12. For help on a particular service:  
  13.   ./hive --service serviceName --help  
  14. Debug help:  ./hive --debug --help  
           咱們能夠看到上邊輸出項Server List,裏邊顯示出Hive支持的服務列表,beeline cli help hiveserver2 hiveserver hwi jar lineage metastore metatool orcfiledump rcfilecat,下面介紹最有用的一些服務

          一、cli:是Command Line Interface 的縮寫,是Hive的命令行界面,用的比較多,是默認服務,直接能夠在命令行裏使用mysql

          二、hiveserver:這個可讓Hive以提供Thrift服務的服務器形式來運行,能夠容許許多個不一樣語言編寫的客戶端進行通訊,使用須要啓動HiveServer服務以和客戶端聯繫,咱們能夠經過設置HIVE_PORT環境變量來設置服務器所監聽的端口,在默認狀況下,端口號爲10000,這個能夠經過如下方式來啓動Hiverserver:linux

          bin/hive --service hiveserver -p 10002程序員

          其中-p參數也是用來指定監聽端口的web

          三、hwi:其實就是hive web interface的縮寫它是hive的web藉口,是hive cli的一個web替代方案sql

          四、jar:與hadoop jar等價的Hive接口,這是運行類路徑中同時包含Hadoop 和Hive類的Java應用程序的簡便方式apache

          五、metastore:在默認的狀況下,metastore和hive服務運行在同一個進程中,使用這個服務,可讓metastore做爲一個單獨的進程運行,咱們能夠經過METASTOE——PORT來指定監聽的端口號編程

 

二:Hive的三種啓動方式

      1, hive  命令行模式

        進入hive安裝目錄,輸入bin/hive的執行程序,或者輸入 hive –service cli

        用於linux平臺命令行查詢,查詢語句基本跟mysql查詢語句相似

       2, hive  web界面的啓動方式

        bin/hive –service hwi  (& 表示後臺運行)

        用於經過瀏覽器來訪問hive,感受沒多大用途,瀏覽器訪問地址是:127.0.0.1:9999/hwi

       3, hive  遠程服務 (端口號10000) 啓動方式

        bin/hive –service hiveserver2  &(&表示後臺運行)

        用java,python等程序實現經過jdbc等驅動的訪問hive就用這種起動方式了,這個是程序員最須要的方式了

三:hiveServer/HiveServer2

       1:簡單介紹     

        二者都容許遠程客戶端使用多種編程語言,經過HiveServer或者HiveServer2,客戶端能夠在不啓動CLI的狀況下對Hive中的數據進行操做,連這個和都容許遠程客戶端使用多種編程語言如java,python等向hive提交請求,取回結果(從hive0.15起就再也不支持hiveserver了),可是在這裏咱們仍是要說一下hiveserver

       HiveServer或者HiveServer2都是基於Thrift的,但HiveSever有時被稱爲Thrift server,而HiveServer2卻不會。既然已經存在HiveServer,爲何還須要HiveServer2呢?這是由於HiveServer不能處理多於一個客戶端的併發請求,這是因爲HiveServer使用的Thrift接口所致使的限制,不能經過修改HiveServer的代碼修正。所以在Hive-0.11.0版本中重寫了HiveServer代碼獲得了HiveServer2,進而解決了該問題。HiveServer2支持多客戶端的併發和認證,爲開放API客戶端如JDBC、ODBC提供更好的支持。

       2:二者的區別

       Hiveserver1 和hiveserver2的JDBC區別: 
       HiveServer version               Connection URL                    Driver Class 

       HiveServer2                          jdbc:hive2://:                          org.apache.hive.jdbc.HiveDriver
       HiveServer1                          jdbc:hive://:                            org.apache.hadoop.hive.jdbc.HiveDriver

       3:學習HiveServer和HiveServer2

       HiveServer:

       在命令行輸入hive --service hiveserver –help查看hiveserver的幫助信息:

 

[html]  view plain  copy
 
 在CODE上查看代碼片派生到個人代碼片
  1. [hadoop@hadoop~]$ hive --service hiveserver --help  
  2. Starting Hive Thrift Server  
  3. usage:hiveserver  
  4. -h,--help                        Print help information  
  5.     --hiveconf <propertyproperty=value>   Use value for given property  
  6.     --maxWorkerThreads <arg>      maximum number of worker threads,  
  7.                                  default:2147483647  
  8.     --minWorkerThreads <arg>      minimum number of worker threads,  
  9.                                   default:100  
  10. -p <port>                        Hive Server portnumber, default:10000  
  11. -v,--verbose                     Verbose mode  

 

       啓動hiveserver服務,能夠得知默認hiveserver運行在端口10000,最小100工做線程,最大2147483647工做線程。

 

[html]  view plain  copy
 
 在CODE上查看代碼片派生到個人代碼片
  1. [hadoop@hadoop~]$ hive --service hiveserver -v  
  2. Starting Hive Thrift Server  
  3. 14/08/01 11:07:09WARN conf.HiveConf: DEPRECATED: hive.metastore.ds.retry.* no longer has anyeffect.  Use hive.hmshandler.retry.*instead  
  4. Starting hive serveron port 10000 with 100 min worker threads and 2147483647 maxworker threads  

 

       以上的hiveserver在hive1.2.1中並不會出現,官網的說法是:

       HiveServer is scheduled to be removed from Hive releases starting Hive 0.15. See HIVE-6977. Please switch over to HiveServer2.

       Hiveserver2

       Hiveserver2容許在配置文件hive-site.xml中進行配置管理,具體的參數爲:

 

[html]  view plain  copy
 
 在CODE上查看代碼片派生到個人代碼片
  1. hive.server2.thrift.min.worker.threads– 最小工做線程數,默認爲5。  
  2. hive.server2.thrift.max.worker.threads – 最小工做線程數,默認爲500。  
  3. hive.server2.thrift.port– TCP 的監聽端口,默認爲10000。  
  4. hive.server2.thrift.bind.host– TCP綁定的主機,默認爲localhost  

 

       也能夠設置環境變量HIVE_SERVER2_THRIFT_BIND_HOST和HIVE_SERVER2_THRIFT_PORT覆蓋hive-site.xml設置的主機和端口號。從Hive-0.13.0開始,HiveServer2支持經過HTTP傳輸消息,該特性當客戶端和服務器之間存在代理中介時特別有用。與HTTP傳輸相關的參數以下:

 

[html]  view plain  copy
 
 在CODE上查看代碼片派生到個人代碼片
  1. hive.server2.transport.mode – 默認值爲binary(TCP),可選值HTTP。  
  2. hive.server2.thrift.http.port– HTTP的監聽端口,默認值爲10001。  
  3. hive.server2.thrift.http.path – 服務的端點名稱,默認爲 cliservice。  
  4. hive.server2.thrift.http.min.worker.threads– 服務池中的最小工做線程,默認爲5。  
  5. hive.server2.thrift.http.max.worker.threads– 服務池中的最小工做線程,默認爲500。  

 

        啓動Hiveserver2有兩種方式,一種是上面已經介紹過的hive --service hiveserver2,另外一種更爲簡潔,爲hiveserver2。使用hive--service hiveserver2 –H或hive--service hiveserver2 –help查看幫助信息:
[html]  view plain  copy
 
 在CODE上查看代碼片派生到個人代碼片
  1. Starting HiveServer2  
  2. Unrecognizedoption: -h  
  3. usage:hiveserver2  
  4. -H,--help                        Print help information  
  5.     --hiveconf <propertyproperty=value>   Use value for given property  
       默認狀況下,HiveServer2以提交查詢的用戶執行查詢(true),若是hive.server2.enable.doAs設置爲false,查詢將以運行hiveserver2進程的用戶運行。爲了防止非加密模式下的內存泄露,能夠經過設置下面的參數爲true禁用文件系統的緩存:
[html]  view plain  copy
 
 在CODE上查看代碼片派生到個人代碼片
  1. fs.hdfs.impl.disable.cache – 禁用HDFS文件系統緩存,默認值爲false。  
  2. fs.file.impl.disable.cache – 禁用本地文件系統緩存,默認值爲false。  

      4:配置使用hiveserver2(Hive 2.0爲例)

        sudo vim hive-site.xml

       1):配置監聽端口和路徑

<property> <name>hive.server2.thrift.port</name> <value>10000</value> </property> <property> <name>hive.server2.thrift.bind.host</name> <value>192.168.48.130</value> </property>

       2):設置impersonation

      這樣hive server會以提交用戶的身份去執行語句,若是設置爲false,則會以起hive server daemon的admin user來執行語句 

 

<property> <name>hive.server2.enable.doAs</name> <value>true</value> </property>
3):hiveserver2節點配置
Hiveserver2已經再也不須要hive.metastore.local這個配置項了(hive.metastore.uris爲空,則表示是metastore在本地,不然
就是遠程)遠程的話直接配置hive.metastore.uris便可
<property>
    <name>hive.metastore.uris</name>
    <value>thrift://xxx.xxx.xxx.xxx:9083</value>
    <description>Thrift URI for the remote metastore. Used by metastore client to con
nect to remote metastore.</description>
  </property>
4):zookeeper配置
[html] view plain copy
 
在CODE上查看代碼片派生到個人代碼片
  1. <property>  
  2.   <name>hive.support.concurrency</name>  
  3.   <description>Enable Hive's Table Lock Manager Service</description>  
  4.   <value>true</value>  
  5. </property>  
  6. <property>  
  7.   <name>hive.zookeeper.quorum</name>  
  8.   <description>Zookeeper quorum used by Hive's Table Lock Manager</description>  
  9.   <value>master1:2181,slave1:2181,slave2:2181</value>  
  10. </property>   
注意:沒有配置hive.zookeeper.quorum會致使沒法併發執行hive ql請求和致使數據異常

       5):hiveserver2的Web UI配置

       Hive 2.0 之後才支持Web UI的,在之前的版本中並不支持

 

[html]  view plain  copy
 
 在CODE上查看代碼片派生到個人代碼片
  1. <property>  
  2.     <name>hive.server2.webui.host</name>  
  3.     <value>192.168.48.130</value>  
  4.     <description>The host address the HiveServer2 WebUI will listen on</description>  
  5.   </property>  
  6.   <property>  
  7.     <name>hive.server2.webui.port</name>  
  8.     <value>10002</value>  
  9.     <description>The port the HiveServer2 WebUI will listen on. This can beset to 0 o  
  10. r a negative integer to disable the web UI</description>  
  11.   </property>  

 

       啓動服務:

       1):啓動metastore

       bin/hive --service metastore &

       默認端口爲9083

       2):啓動hiveserver2

       bin/hive --service hiveserver2 &

       3):測試

       Web UI:http://192.168.48.130:10002/

   

          使用beeline控制檯控制hiveserver2

          啓動beeline :bin/beeline

          鏈接:!connect jdbc:hive2://192.168.48.130:10000 hive hive   

          出現錯誤: org.apache.hadoop.ipc.RemoteException(org.apache.hadoop.security.authorize.AuthorizationException): User: master is not allowed to impersonate hive (state=,code=0)

          解決辦法:http://www.aboutyun.com/blog-331-2956.html

          PS:小編在這裏並無解決,由於這個beeline基本用不到,因此就暫時放放了,後期若是須要的話再來解決它

相關文章
相關標籤/搜索