为了提高hive可用性,提高集群的稳定性。对已经搭建好的hive进行高可用改造。没有搭建好hive的童鞋,请先自行搭建好hive,再来参考本文。
<property>
<name>hive.server2.support.dynamic.service.discoveryname>
<value>truevalue>
property>
<property>
<name>hive.server2.zookeeper.namespacename>
<value>hiveserver2_zkvalue>
property>
<property>
<name>hive.zookeeper.quorumname>
<value>hdp11,hdp12,hdp13value>
property>
<property>
<name>hive.zookeeper.client.portname>
<value>2181value>
property>
<property>
scp /opt/bigdata/hive
<property>
<name>hive.server2.thrift.bind.hostname>
<value>hdp12value>
property>
hiveservice.sh start
ls /hiveserver2_zk
注意需要等待一会,hiveserver2启动得比较慢
查看hive的hiveserver2日志发现报错信息:
2021-03-01 19:44:15,923 WARN [main] server.HiveServer2 (HiveServer2.java:startHiveServer2(1064)) - Error starting HiveServer2 on attempt 1, will retry in 60000ms
java.lang.NoClassDefFoundError: org/apache/tez/dag/api/TezConfiguration
at org.apache.hadoop.hive.ql.exec.tez.TezSessionPoolSession$AbstractTriggerValidator.startTriggerValidator(TezSessionPoolSession.java:74)
at org.apache.hadoop.hive.ql.exec.tez.TezSessionPoolManager.initTriggers(TezSessionPoolManager.java:207)
at org.apache.hadoop.hive.ql.exec.tez.TezSessionPoolManager.startPool(TezSessionPoolManager.java:114)
at org.apache.hive.service.server.HiveServer2.initAndStartTezSessionPoolManager(HiveServer2.java:839)
at org.apache.hive.service.server.HiveServer2.startOrReconnectTezSessions(HiveServer2.java:822)
at org.apache.hive.service.server.HiveServer2.start(HiveServer2.java:745)
at org.apache.hive.service.server.HiveServer2.startHiveServer2(HiveServer2.java:1037)
at org.apache.hive.service.server.HiveServer2.access$1600(HiveServer2.java:140)
at org.apache.hive.service.server.HiveServer2$StartOptionExecutor.execute(HiveServer2.java:1305)
at org.apache.hive.service.server.HiveServer2.main(HiveServer2.java:1149)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.apache.hadoop.util.RunJar.run(RunJar.java:318)
at org.apache.hadoop.util.RunJar.main(RunJar.java:232)
Caused by: java.lang.ClassNotFoundException: org.apache.tez.dag.api.TezConfiguration
at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 16 more
这个信息是缺少Tez引擎导致的,不影响使用,可通过安装Tez来解决。
控制台输入: beeline 打开窗口
在窗口中输入:
!connect jdbc:hive2://hdp11,hdp12/;serviceDiscoveryMode=zooKeeper;zooKeeperNamespace=hiveserver2_zk along root
。。。
在hdp12上,杀掉占用10000端口的进程,即杀掉hdp12的hiveServer2进程
[along@hdp12 logs]$ netstat -ntpl |grep 10000
(Not all processes could be identified, non-owned process info
will not be shown, you would have to be root to see it all.)
tcp6 0 0 :::10000 :::* LISTEN 87776/java
在hdp12上打开beeline,连接
beeline> !connect jdbc:hive2://hdp11,hdp12/;serviceDiscoveryMode=zooKeeper;zooKeeperNamespace=hiveserver2_zk
连接成功
Connected to: Apache Hive (version 3.1.2)
Driver: Hive JDBC (version 3.1.2)
Transaction isolation: TRANSACTION_REPEATABLE_READ
0: jdbc:hive2://hdp11,hdp12/>
0: jdbc:hive2://hdp11,hdp12/>
0: jdbc:hive2://hdp11,hdp12/>
0: jdbc:hive2://hdp11,hdp12/>
0: jdbc:hive2://hdp11,hdp12/> show databases;
+----------------------+
| database_name |
+----------------------+
| default |
再查看zk中的命名空间:
[zk: localhost:2181(CONNECTED) 35] ls /hiveserver2_zk
[serverUri=hdp12:10000;version=3.1.2;sequence=0000000017]
<property>
<name>hive.metastore.urisname>
<value>thrift://hdp11:9083,thrift://hdp12:9083value>
property>
[along@hdp11 /]$ hiveservices.sh status
Metastore服务运行正常
HiveServer2服务运行正常
[along@hdp11 logs]$ beeline
Beeline version 3.1.2 by Apache Hive
beeline> !connect jdbc:hive2://hdp11,hdp12/;serviceDiscoveryMode=zooKeeper;zooKeeperNamespace=hiveserver2_zk
查询语句
0: jdbc:hive2://hdp11,hdp12/> show tables;
+-----------------------------+
| tab_name |
+-----------------------------+
| dwd_action_log |
| dwd_dim_activity_info |
| dwd_dim_base_province |
[along@hdp11 /]$ ps -ef | grep metastore
along 3751 1 1 17:21 pts/1 00:00:09 /opt/bigdata/jdk1.8.0_212/bin/java -Dproc_jar -Dproc_metastore
……
/opt/bigdata/hive/lib/hive-metastore-3.1.2.jar org.apache.hadoop.hive.metastore.HiveMetaStore
along 5031 1367 0 17:33 pts/0 00:00:00 grep --color=auto metastore
[along@hdp11 /]$ kill -9 3751
[along@hdp11 /]$ hiveservices.sh status
Metastore服务运行异常
HiveServer2服务运行正常
执行查询语句,高可用验证完成
0: jdbc:hive2://hdp11,hdp12/> show tables;
+-----------------------------+
| tab_name |
+-----------------------------+
| dwd_action_log |
| dwd_dim_activity_info |
| dwd_dim_base_province |
Metastore服务运行异常
HiveServer2服务运行正常
执行查询语句,高可用验证完成
```sql
0: jdbc:hive2://hdp11,hdp12/> show tables;
+-----------------------------+
| tab_name |
+-----------------------------+
| dwd_action_log |
| dwd_dim_activity_info |
| dwd_dim_base_province |