java 通过zookeeper连接hiveserver2报错:org.apache.hive.jdbc.ZooKeeperHiveClientException: Unable to read Hi

环境: hive驱动版本:1.2.1

通过以下连接方式,通过hiveserver2 url  jdbc:hive2://prddn01.com:10000/;principal=hive/[email protected] 连接hiveserver2完全正确,但是换成zookeeper url就报错:

package com.asiainfo;

import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.security.UserGroupInformation;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.scheduling.annotation.EnableScheduling;

/*
 * 开启定时任务
 */
@EnableScheduling   //开启定时任务
@SpringBootApplication(scanBasePackages = {"com.asiainfo.*"})
public class SpringbootMybatisApplication {

	public static void main(String[] args) throws SQLException {
		SpringApplication.run(SpringbootMybatisApplication.class, args);
		Configuration configuration = new Configuration();
		configuration.set("hadoop.security.authentication", "Kerberos");
		configuration.set("keytab.file", "/data02/dcadmin/keytab_shengchan/dcadmin.keytab");
		configuration.set("kerberos.principal", "[email protected]");
		UserGroupInformation.setConfiguration(configuration);
		try {
			UserGroupInformation.loginUserFromKeytab("[email protected]", "/data02/dcadmin/keytab_shengchan/dcadmin.keytab");
		} catch (IOException e) {
			e.printStackTrace();
			System.out.println("qweasd");
		}
		Connection connection = null;
		ResultSet rs = null;
		PreparedStatement ps = null;
		try {
			Class.forName("org.apache.hive.jdbc.HiveDriver");
			//connection = DriverManager.getConnection("jdbc:hive2://prddn01.com:10000/;principal=hive/[email protected]", "dcadmin", "");
			connection = DriverManager.getConnection("jdbc:hive2://pr01.com:2181,pr022.com:2181/;serviceDiscoveryMode=zooKeeper;zooKeeperNamespace=hiveserver2?tez.queue.name=offline");
			if (null != connection) {
				ps = connection.prepareStatement("SELECT * FROM test limit 5");
				rs = ps.executeQuery();
				while (rs.next())
					System.out.println(rs);
					System.out.println(rs.getInt(1));
			}
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			if (rs != null)
				rs.close();
			if (ps != null)
				ps.close();
			if (connection != null)
				connection.close();
		}
	}
}
log4j:WARN No appenders could be found for logger (org.springframework.core.env.StandardEnvironment).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::        (v2.2.7.RELEASE)

java.sql.SQLException: Could not open client transport for any of the Server URI's in ZooKeeper: Unable to read HiveServer2 uri from ZooKeeper
        at org.apache.hive.jdbc.HiveConnection.openTransport(HiveConnection.java:219)
        at org.apache.hive.jdbc.HiveConnection.(HiveConnection.java:176)
        at org.apache.hive.jdbc.HiveDriver.connect(HiveDriver.java:105)
        at java.sql.DriverManager.getConnection(DriverManager.java:664)
        at java.sql.DriverManager.getConnection(DriverManager.java:270)
        at com.asiainfo.SpringbootMybatisApplication.main(SpringbootMybatisApplication.java:41)
        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.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:48)
        at org.springframework.boot.loader.Launcher.launch(Launcher.java:87)
        at org.springframework.boot.loader.Launcher.launch(Launcher.java:51)
        at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:52)
Caused by: org.apache.hive.jdbc.ZooKeeperHiveClientException: Unable to read HiveServer2 uri from ZooKeeper
        at org.apache.hive.jdbc.ZooKeeperHiveClientHelper.getNextServerUriFromZooKeeper(ZooKeeperHiveClientHelper.java:86)
        at org.apache.hive.jdbc.Utils.updateConnParamsFromZooKeeper(Utils.java:532)
        at org.apache.hive.jdbc.HiveConnection.openTransport(HiveConnection.java:217)
        ... 13 more
Caused by: org.apache.hive.jdbc.ZooKeeperHiveClientException: Tried all existing HiveServer2 uris from ZooKeeper.
        at org.apache.hive.jdbc.ZooKeeperHiveClientHelper.getNextServerUriFromZooKeeper(ZooKeeperHiveClientHelper.java:73)
        ... 15 more

报错原因:

 1.hive驱动版本太低(我是这个原因,hive客户端版本 1.2.1,我换成 2.0.0版本能正常运行)



	org.apache.hive
	hive-jdbc
	2.0.0

 

你可能感兴趣的:(hive,Unable,to,read,HiveServer2,uri,from,ZooKeeper,zookeeper连接,hiveserver2报错)