Hive远程访问服务

概述

HiveServer2是一个服务接口,能够允许远程的客户端去执行SQL请求且得到检索结果。HiveServer2的实现,依托于ThriftRPC,是HiveServer的提高版本,它被设计用来提供更好的支持对于open API例如JDBC和ODBC。

准备

关闭hadoop组件

1
stop-all.sh

配置

修改hive-site.xml(hive组件下)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
<!-- 添加一下内容 hive.server2.thrift.clien需填写自己的linux用户和密码,已进行注释,不写此项配置并不影响hiveserver2-->

<property>
          <!-- HiveServer2 -->
      <name>hive.server2.thrift.port</name>
      <value>10000</value>
  </property>

  <property>
      <name>hive.server2.thrift.bind.host</name>
      <value>10.0.0.10</value>
  </property>
<!--
  <property>
      <name>hive.server2.thrift.client.user</name>
      <value>Linux用户</value>
      <description>Username to use against thrift client</description>
  </property>

  <property>
      <name>hive.server2.thrift.client.password</name>
      <value>Linux用户密码</value>
      <description>Password to use against thrift client</description>
  </property>
-->

修改core-site.xml(hadoop组件下)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
<!-- hive.server2.thrift.client hive-site.xml如果写了话,这里就要同步写入相同内容 -->
<!--
  <property>
      <name>hive.server2.thrift.client.user</name>
      <value>linux用户</value>
      <description>Username to use against thrift client</description>
  </property>

  <property>
      <name>hive.server2.thrift.client.password</name>
      <value>密码</value>
      <description>Password to use against thrift client</description>
  </property>
-->

<!-- 用户“root”可以代理所有主机上的所有用户 -->
  <property>
<!-- 非root用户请把下面name中的root换成你自己的用户名 -->
      <name>hadoop.proxyuser.root.hosts</name>
      <value>*</value>
  </property>

  <property>
<!-- 非root用户请把下面name中的root换成你自己的用户名 -->
      <name>hadoop.proxyuser.root.groups</name>
      <value>*</value>
  </property>

测试

后台开启Hiveserver2服务

新开终端使用beeline连接

1
2
3
!connect jdbc:hive2://IP地址:10000
# 提示输入用户(可直接回车)
# 提示输入密码(可直接回车)