73.1 演示环境介绍
- Hive版本必须0.14or以上
- CM和CDH版本:5.13.0
- 未启用Kerberos
73.2 操作演示
- 在HiveServer2中增加如下配置
- 保存配置,根据提示重启服务
<property>
<name>hive.server2.support.dynamic.service.discovery</name>
<value>true</value>
</property>
<property>
<name>hive.server2.zookeeper.namespace</name>
<value>hiveserver2_zk</value>
</property>
<property>
<name>hive.zookeeper.quorum</name>
<value>ip-186-31-10-118.fayson.com:2181,ip-186-31-5-190.fayson.com:2181,ip-186-31-6-148.fayson.com:2181</value>
</property>
<property>
<name>hive.zookeeper.client.port</name>
<value>2181</value>
</property>
- 通过zookeeper-client命令查看,HiveServer2已在Zookeeper注册成功
[root@ip-186-31-6-148 ~]# zookeeper-client
[zk: localhost:2181(CONNECTED) 0] ls /
[hiveserver2_zk, hive_zookeeper_namespace_hive, hbase, zookeeper]
[zk: localhost:2181(CONNECTED) 1] ls /hiveserver2_zk
[serverUri=ip-186-31-6-148.fayson.com:10000;version=1.1.0-cdh5.13.0;sequence=0000000006, serverUri=ip-186-31-5-190.fayson.com:10000;version=1.1.0-cdh5.13.0;sequence=0000000005]
[zk: localhost:2181(CONNECTED) 25]
- HiveServer2注册Zookeeper后,JDBC连接的URL格式为:
jdbc:hive2://<zookeeper quorum>/<dbName>;ServiceDiscoveryMode=zookeeper;zooKeeperNameSpace=hiveserver2
- Beeline连接HiveServer2服务
[root@ip-186-31-6-148 ~]# beeline
beeline> !connect jdbc:hive2://ip-186-31-10-118.fayson.com:2181,ip-186-31-5-190.fayson.com:2181,ip-186-31-6-148.fayson.com:2181/;serviceDiscoveryMode=zooKeeper;zooKeeperNamespace=hiveserver2_zk
....
17/11/10 08:23:26 [main]: INFO jdbc.HiveConnection: Connected to ip-186-31-6-148.fayson.com:10000
...
0: jdbc:hive2://ip-186-31-10-118.fayson.com:2> select * from test;
...
INFO : OK
+----------+----------+--+
| test.s1 | test.s2 |
+----------+----------+--+
| 11 | 222 |
+----------+----------+--+
1 row selected (3.516 seconds)
0: jdbc:hive2://ip-186-31-10-118.fayson.com:2>
- 停止ip-186-31-6-148.fayson.com的HivServer2服务
- Beeline再次连接
[root@ip-186-31-6-148 ~]# beeline
beeline> !connect jdbc:hive2://ip-186-31-10-118.fayson.com:2181,ip-186-31-5-190.fayson.com:2181,ip-186-31-6-148.fayson.com:2181/;serviceDiscoveryMode=zooKeeper;zooKeeperNamespace=hiveserver2_zk
...
17/11/10 08:34:27 [main]: INFO jdbc.HiveConnection: Connected to ip-186-31-5-190.fayson.com:10000
0: jdbc:hive2://ip-186-31-10-118.fayson.com:2> select * from test;
+----------+----------+--+
| test.s1 | test.s2 |
+----------+----------+--+
| 11 | 222 |
+----------+----------+--+
1 row selected (2.103 seconds)
0: jdbc:hive2://ip-186-31-10-118.fayson.com:2>
大数据视频推荐:
腾讯课堂
CSDN
大数据语音推荐:
企业级大数据技术应用
大数据机器学习案例之推荐系统
自然语言处理
大数据基础
人工智能:深度学习入门到精通