Hive学习之HiveServer2服务端配置与启动

本文对比介绍了Hive中的两种服务:HiveServer和HiveServer2。HiveServer因仅支持单个客户端并发请求而存在局限性;HiveServer2则通过支持多客户端并发请求和认证,提供更强大的功能,包括对JDBC和ODBC的支持。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

    在之前的学习和实践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提供了更好的支持。

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

[plain]  view plain  copy
 print ? 在CODE上查看代码片 派生到我的代码片
  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  

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

[plain]  view plain  copy
 print ? 在CODE上查看代码片 派生到我的代码片
  1. [hadoop@hadoop~]$ hive --service hiveserver --help  
  2. Starting Hive Thrift Server  
  3. usage:hiveserver  
  4.  -h,--help                        Print help information  
  5.     --hiveconf <property=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工作线程。

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

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

[plain]  view plain  copy
 print ? 在CODE上查看代码片 派生到我的代码片
  1. hive.server2.thrift.min.worker.threads– 最小工作线程数,默认为5。  
[plain]  view plain  copy
 print ? 在CODE上查看代码片 派生到我的代码片
  1. hive.server2.thrift.max.worker.threads – 最小工作线程数,默认为500。  
  2. hive.server2.thrift.port– TCP 的监听端口,默认为10000。  
  3. 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
 print ? 在CODE上查看代码片 派生到我的代码片
  1. hive.server2.transport.mode – 默认值为binary(TCP),可选值HTTP。  
  2. hive.server2.thrift.http.port– HTTP的监听端口,默认值为10001。  
[plain]  view plain  copy
 print ? 在CODE上查看代码片 派生到我的代码片
  1. hive.server2.thrift.http.path – 服务的端点名称,默认为 cliservice。  
  2. hive.server2.thrift.http.min.worker.threads– 服务池中的最小工作线程,默认为5。  
  3. 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
 print ? 在CODE上查看代码片 派生到我的代码片
  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以提交查询的用户执行查询(true),如果hive.server2.enable.doAs设置为false,查询将以运行hiveserver2进程的用户运行。为了防止非加密模式下的内存泄露,可以通过设置下面的参数为true禁用文件系统的缓存:

     

[plain]  view plain  copy
 print ? 在CODE上查看代码片 派生到我的代码片
  1. fs.hdfs.impl.disable.cache – 禁用HDFS文件系统缓存,默认值为false。  
  2. fs.file.impl.disable.cache – 禁用本地文件系统缓存,默认值为false。  
在Linux上配置Hive时,`hitesite.xml`是一个重要配置文件,它包含了HiveServer2服务的连接信息和其他设置。如果之前的内容被误删并无法恢复,你可以按照以下步骤尝试重启HiveServer2: 1. **备份现有文件**:首先,创建一个新的`hitesite.xml`备份原文件,以防后续需要参考原始配置。 ```bash cp /path/to/hiveserver2/conf/hitesite.xml /path/to/hitesite.xml.bak ``` 2. **检查基本配置**:确认`conf`目录下还有其他必要的配置文件,如`core-site.xml`, `hdfs-site.xml`, 和`hive-env.sh`等。确保这些文件存在且内容完整。 3. **重新编写hitesite.xml**:打开`hitesite.xml`,根据Hive官方文档或你之前的记录添加必需的服务端配置,例如主机名、端口、 Thrift服务器的启用等。 4. **清理缓存和日志**:清除HiveService2的旧数据,包括可能的错误日志以及Metastore的数据缓存。 ```bash rm -rf /path/to/hivevar/lib/hive || true sudo service hive-server2 stop sudo rm -rf /path/to/hadoop/var/log/hive || true ``` 5. **重新启动服务**:再次尝试启动HiveServer2服务。 ```bash sudo service hive-server2 start ``` 6. **验证服务是否运行**:通过命令行工具,如`jps`检查HiveServer2进程是否已在后台运行,并尝试连接到Hive,看是否能成功。 如果你在以上步骤中遇到问题,可以检查以下几个方面: - 配置语法是否正确。 - 是否有权限访问所有必需的资源。 - 确保Hadoop集群环境已经配置好并且可用。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值