HiveServer2服务端配置与启动

        在以前的学习和实践Hive中,使用的都是CLI或者hive –e的方式,该方式仅容许使用HiveQL执行查询、更新等操做,而且该方式比较笨拙单一。幸亏Hive提供了轻客户端的实现,经过HiveServer或者HiveServer2,客户端能够在不启动CLI的状况下对Hive中的数据进行操做,二者都容许远程客户端使用多种编程语言如Java、Python向Hive提交请求,取回结果。HiveServer或者HiveServer2都是基于Thrift的,但HiveSever有时被称为Thrift server,而HiveServer2却不会。既然已经存在HiveServer为何还须要HiveServer2呢?这是由于HiveServer不能处理多于一个客户端的并发请求,这是因为HiveServer使用的Thrift接口所致使的限制,不能经过修改HiveServer的代码修正。所以在Hive-0.11.0版本中重写了HiveServer代码获得了HiveServer2,进而解决了该问题。HiveServer2支持多客户端的并发和认证,为开放API客户端如JDBC、ODBC提供了更好的支持。html

       既然HiveServer2提供了更强大的功能,将会对其进行着重学习,但也会简单了解一下HiveServer的使用方法。在命令中输入hive --service help,结果以下。从结果能够了解到,能够使用hive <parameters> --service serviceName <serviceparameters>启动特定的服务,如cli、hiverserver、hiveserver2等。apache

[plain]  view plain  copy
  1. [hadoop@hadoop~]$ hive --service  help  
  2. Usage ./hive<parameters> --service serviceName <service parameters>  
  3. Service List: beelinecli help hiveserver2 hiveserver hwi jar lineage metastore metatool orcfiledumprcfilecat schemaTool version  
  4. Parametersparsed:  
  5.   --auxpath : Auxillary jars  
  6.   --config : Hive configuration directory  
  7.   --service : Starts specificservice/component. cli is default  
  8. Parameters used:  
  9.   HADOOP_HOME or HADOOP_PREFIX : Hadoop installdirectory  
  10.   HIVE_OPT : Hive options  
  11. For help on aparticular service:  
  12.   ./hive --service serviceName --help  
  13. Debug help:  ./hive --debug --help  

    启动hiveserver服务,能够得知默认hiveserver运行在端口10000,最小100工做线程,最大2147483647工做线程。编程

[plain]  view plain  copy
  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  

       接下来学习更强大的hiveserver2。Hiveserver2容许在配置文件hive-site.xml中进行配置管理,具体的参数为:w plain co缓存

[plain]  view plain  copy
  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传输相关的参数以下:服务器

[plain]  view plain  copy
  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查看帮助信息:并发

[plain]  view plain  copy
  1. Starting HiveServer2  
  2. Unrecognizedoption: -h  
  3. usage:hiveserver2  
  4.  -H,--help                        Print help information  
  5.     --hiveconf <property=value>   Use value for given property  

        中止hiveserver2:编程语言

        运行jps发现除了hadoop运行的进程外还有一个5757 RunJar,执行kill -9 5757
oop


      默认状况下,HiveServer2以提交查询的用户执行查询(true),若是hive.server2.enable.doAs设置为false,查询将以运行hiveserver2进程的用户运行。为了防止非加密模式下的内存泄露,能够经过设置下面的参数为true禁用文件系统的缓存:学习

fs.hdfs.impl.disable.cache – 禁用HDFS文件系统缓存,默认值为false。  
fs.file.impl.disable.cache – 禁用本地文件系统缓存,默认值为false。

默认状况下hiveserver不支持update和delete操做,所以会出现以下问题:加密

hive安装后须要修改已建的表及查询操做,在执行修改操做时遇到了以下问题。


hive> update dp set name='beijing' where id=1159;
FAILED: SemanticException [Error 10294]: Attempt to do update or delete using transaction manager that does not support these operations.

在hive-site.xml文件中,增长以下属性。

<property>
    <name>hive.support.concurrency</name>
    <value>true</value>
  </property>
    <property>
    <name>hive.enforce.bucketing</name>
    <value>true</value>
  </property>
    <property>
    <name>hive.exec.dynamic.partition.mode</name>
    <value>nonstrict</value>
  </property>
  <property>
    <name>hive.txn.manager</name>
    <value>org.apache.hadoop.hive.ql.lockmgr.DbTxnManager</value>
  </property>
    <property>
    <name>hive.compactor.initiator.on</name>
    <value>true</value>
  </property>
  <property>
    <name>hive.compactor.worker.threads</name>
    <value>1</value>
  </property>
  <property>
    <name>hive.in.test</name>
    <value>true</value>
  </property>