[英]Unable to connect to Hive from Eclipse
I'm new to Big Data/Hadoop. 我是大数据/ Hadoop的新手。 I'm trying to connect to Hive from Eclipse using JDBC.
我正在尝试使用JDBC从Eclipse连接到Hive。 I keep getting the following error.
我不断收到以下错误。 I have no idea what's going on.
我不知道发生了什么事。 Please help.
请帮忙。
ERROR StatusLogger No log4j2 configuration file found.
错误StatusLogger找不到log4j2配置文件。 Using default configuration: logging only errors to the console.
使用默认配置:仅将错误记录到控制台。 SLF4J: Class path contains multiple SLF4J bindings.
SLF4J:类路径包含多个SLF4J绑定。 SLF4J: Found binding in [jar:file:/C:/Users/eragank/.m2/repository/org/apache/logging/log4j/log4j-slf4j-impl/2.4.1/log4j-slf4j-impl-2.4.1.jar!/org/slf4j/impl/StaticLoggerBinder.class] SLF4J: Found binding in [jar:file:/C:/Users/eragank/.m2/repository/org/slf4j/slf4j-log4j12/1.6.1/slf4j-log4j12-1.6.1.jar!/org/slf4j/impl/StaticLoggerBinder.class] SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J:在[jar:file:/ C:/Users/eragank/.m2/repository/org/apache/logging/log4j/log4j-slf4j-impl/2.4.1/log4j-slf4j-impl-2.4.1中找到绑定.jar!/org/slf4j/impl/StaticLoggerBinder.class] SLF4J:在[jar:file:/ C:/Users/eragank/.m2/repository/org/slf4j/slf4j-log4j12/1.6.1/slf4j中找到绑定-log4j12-1.6.1.jar!/org/slf4j/impl/StaticLoggerBinder.class] SLF4J:有关说明,请参见http://www.slf4j.org/codes.html#multiple_bindings 。 SLF4J: Actual binding is of type [org.apache.logging.slf4j.Log4jLoggerFactory] Exception in thread "main" java.io.IOException: Login failure for hive/mksd1dlllytj001.c.iron-potion-771.internal@IHGEXT.GLOBAL from keytab /etc/security/keytabs/hive.service.keytab: javax.security.auth.login.LoginException: Unable to obtain password from user at org.apache.hadoop.security.UserGroupInformation.loginUserFromKeytab(UserGroupInformation.java:935) at com.ihg.test.Test.main(Test.java:32)
SLF4J:实际绑定的类型为[org.apache.logging.slf4j.Log4jLoggerFactory]线程“ main”中的异常java.io.IOException:hive/mksd1dlllytj001.c.iron-potion-771.internal@IHGEXT.GLOBAL的登录失败来自keytab /etc/security/keytabs/hive.service.keytab:javax.security.auth.login.LoginException:无法从org.apache.hadoop.security.UserGroupInformation.loginUserFromKeytab(UserGroupInformation.java:935)处的用户获取密码在com.ihg.test.Test.main(Test.java:32)
Caused by: javax.security.auth.login.LoginException: Unable to obtain password from user at com.sun.security.auth.module.Krb5LoginModule.promptForPass(Krb5LoginModule.java:897) at com.sun.security.auth.module.Krb5LoginModule.attemptAuthentication(Krb5LoginModule.java:760)引起原因:javax.security.auth.login.LoginException:无法从com.sun.security.auth.module上的com.sun.security.auth.module.Krb5LoginModule.promptForPass(Krb5LoginModule.java:897)处的用户获取密码。 .Krb5LoginModule.attemptAuthentication(Krb5LoginModule.java:760)
at com.sun.security.auth.module.Krb5LoginModule.login(Krb5LoginModule.java:617)在com.sun.security.auth.module.Krb5LoginModule.login(Krb5LoginModule.java:617)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)在sun.reflect.NativeMethodAccessorImpl.invoke0(本机方法)处
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)在sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)在sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)在java.lang.reflect.Method.invoke(Method.java:498)
at javax.security.auth.login.LoginContext.invoke(LoginContext.java:755)在javax.security.auth.login.LoginContext.invoke(LoginContext.java:755)
at javax.security.auth.login.LoginContext.access$000(LoginContext.java:195)在javax.security.auth.login.LoginContext.access $ 000(LoginContext.java:195)
at javax.security.auth.login.LoginContext$4.run(LoginContext.java:682)在javax.security.auth.login.LoginContext $ 4.run(LoginContext.java:682)
at javax.security.auth.login.LoginContext$4.run(LoginContext.java:680)在javax.security.auth.login.LoginContext $ 4.run(LoginContext.java:680)
at java.security.AccessController.doPrivileged(Native Method)在java.security.AccessController.doPrivileged(本机方法)
at javax.security.auth.login.LoginContext.invokePriv(LoginContext.java:680)在javax.security.auth.login.LoginContext.invokePriv(LoginContext.java:680)
at javax.security.auth.login.LoginContext.login(LoginContext.java:587)在javax.security.auth.login.LoginContext.login(LoginContext.java:587)
at org.apache.hadoop.security.UserGroupInformation.loginUserFromKeytab(UserGroupInformation.java:926) ... 1 more在org.apache.hadoop.security.UserGroupInformation.loginUserFromKeytab(UserGroupInformation.java:926)...还有1
Test.java Test.java
package com.test.Test;
import java.sql.SQLException;
import java.io.IOException;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.Properties;
import org.apache.hadoop.security.UserGroupInformation;
import org.apache.hive.jdbc.HiveDriver;
import java.sql.DriverManager;
public class Test {
private static String driverName = "org.apache.hive.jdbc.HiveDriver";
/**
* @param args
* @throws SQLException
* @throws IOException
*/
public static void main(String[] args) throws SQLException, IOException {
try {
Class.forName(driverName);
System.out.println("Class FOUND!!");
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
System.exit(1);
}
org.apache.hadoop.conf.Configuration conf = new org.apache.hadoop.conf.Configuration();
conf.set("hadoop.security.authentication", "Kerberos");
UserGroupInformation.setConfiguration(conf);
UserGroupInformation.loginUserFromKeytab("hive/mksd1dlllytj001.c.iron-potion-771.internal@IHGEXT.GLOBAL", "/etc/security/keytabs/hive.service.keytab");
//replace "hive" here with the name of the user the queries should run as
Connection con = DriverManager.getConnection("jdbc:hive2://mksd1dlllytj001.c.iron-potion-771.internal:10000/grs_core?transportMode=http;httpPath=cliservice;auth=kerberos;sasl.qop=auth-int;principal=hive/mksd1dlllytj001.c.iron-potion-771.internal@IHGEXT.GLOBAL", "hive", "");
//Connection con = DriverManager.getConnection("jdbc:hive2://mksd1dlllytj001.c.iron-potion-771.internal:10000/;principal=hive/mksd1dlllytj001.c.iron-potion-771.internal@IHGEXT.GLOBAL;transportMode=http;httpPath=cliservice");
// HiveDriver hd=new HiveDriver();
// System.out.println("HDB CON..");
//
// Connection con2= hd.connect("jdbc:hive2://mksd1dlllytj001.c.iron-potion-771.internal:10000/grs_core?transportMode=http;httpPath=cliservice;auth=kerberos;sasl.qop=auth-int");
//
// System.out.println("HDB CONN="+con2);
//
//;principal=hive/node.addr@ABCREALM.LOCAL
Statement stmt = con.createStatement();
/*String tableName = "testHiveDriverTable";
stmt.execute("drop table if exists " + tableName);
stmt.execute("create table " + tableName + " (key int, value string)");
// show tables
// String sql = "show tables '" + tableName + "'"; */
String sql = ("show tables;");
ResultSet res = stmt.executeQuery(sql);
if (res.next()) {
System.out.println(res.getString(1));
}
}
}
POM.xml POM.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.ihg.ptfwork</groupId>
<artifactId>ptfUpdateTest</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>ptfUpdateTest</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<env.hiveVersion>1.2.1000.2.6.0.3-8</env.hiveVersion>
<env.hivecoreDir>/usr/hdp/current/hive-client/conf</env.hivecoreDir>
<env.hivecoreFile>hive-site.xml</env.hivecoreFile>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.hive</groupId>
<artifactId>hive-jdbc</artifactId>
<version>2.0.0</version>
</dependency>
<dependency>
<groupId>org.apache.hive</groupId>
<artifactId>hive-beeline</artifactId>
<version>2.0.0</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>jdk.tools</groupId>
<artifactId>jdk.tools</artifactId>
<version>1.7.0_05</version>
<scope>system</scope>
<systemPath>${JAVA_HOME}/lib/tools.jar</systemPath>
</dependency>
</dependencies>
</project>
I would first try to login without using UserGroupInformation
, you should be able to connect simply using the DriverManager.getConnection()
, I do the same with an h2 database and it works fine. 我将首先尝试不使用
UserGroupInformation
进行登录,您应该能够仅使用DriverManager.getConnection()
进行连接,我对h2数据库也是如此,并且工作正常。 It sounds like it is an issue with the authentication process you are trying to use which I am not very familiar with. 听起来您尝试使用的身份验证过程存在问题,而我对此并不十分熟悉。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.