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基本用不到,因此就暂时放放了,后期若是须要的话再来解决它

相关文章
相关标签/搜索