尝试从Java到配置单元打开jdbc连接时,GSS启动失败

时间:2018-06-21 14:35:48

标签: java hadoop hive kerberos

在Windows PC上运行时,我试图从Java应用程序打开jdbc连接。

Hive已安装在oracle linux服务器上。我正在使用kerberos进行安全身份验证。当keytab在linux服务器上运行时,我使用keytab取得票证。它运作完美。在建立连接之前,我在Windows pc中获得了用于创建票证的keytab文件。

我的Java代码是

import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import org.apache.hadoop.security.UserGroupInformation;

public class Ana {
    private static String driverName = "org.apache.hive.jdbc.HiveDriver";
    public static void main(String[] args) throws SQLException, IOException {
        try {
            org.apache.hadoop.conf.Configuration conf = new org.apache.hadoop.conf.Configuration();
            conf.set("hadoop.security.authentication", "Kerberos");
            conf.set("hive.server2.authentication", "Kerberos");
            UserGroupInformation.setConfiguration(conf);
            UserGroupInformation.loginUserFromKeytab(
                    "neverwinter@FW.XXX.COM.TR", "C:\\Users\\neverwinter\\Documents\\calisan\\yeni2\\neverwinter.keytab");
            Class.forName(driverName);
        } catch ( ClassNotFoundException e ) {
            e.printStackTrace();
            System.exit(1);
        }
        Connection con = DriverManager
                .getConnection("jdbc:hive2://myHost:10000/TGAR;principal=hive/neverwinter@FW.XXX.COM.TR");
        Statement stmt = con.createStatement();
        String tableName = "newTable";
        stmt.execute("drop table if exists " + tableName);
        stmt.execute("create table " + tableName + " (key int, value string)");
    }
}

我的pom xml是

<dependency>
    <groupId>org.apache.hive</groupId>
    <artifactId>hive-jdbc</artifactId>
    <version>1.2.1</version>
            <exclusions>
            <exclusion>
            <groupId>jdk.tools</groupId>
            <artifactId>jdk.tools</artifactId>
        </exclusion>
    </exclusions>
</dependency>
<dependency>
      <groupId>org.apache.hive</groupId>
      <artifactId>hive-exec</artifactId>
      <version>0.13.0</version>
</dependency>
<dependency>
      <groupId>org.apache.hive</groupId>
      <artifactId>hive-jdbc</artifactId>
      <version>0.13.0</version>
</dependency>
<dependency>
      <groupId>org.apache.thrift</groupId>
      <artifactId>libthrift</artifactId>
      <version>0.9.0</version>
</dependency>
<dependency>
      <groupId>org.apache.thrift</groupId>
      <artifactId>libfb303</artifactId>
      <version>0.9.0</version>
</dependency>
<dependency>
      <groupId>commons-logging</groupId>
      <artifactId>commons-logging</artifactId>
      <version>1.1.3</version>
</dependency>
<dependency>
      <groupId>org.apache.hadoop</groupId>
      <artifactId>hadoop-client</artifactId>
      <version>2.6.0</version>
</dependency>

在getConnection行时,它将引发以下错误:

  

由以下原因引起:org.apache.thrift.transport.TTransportException:GSS   发起失败于   org.apache.thrift.transport.TSaslTransport.sendAndThrowMessage(TSaslTransport.java:221)     在   org.apache.thrift.transport.TSaslTransport.open(TSaslTransport.java:297)     在   org.apache.thrift.transport.TSaslClientTransport.open(TSaslClientTransport.java:37)     在   org.apache.hadoop.hive.thrift.client.TUGIAssumingTransport $ 1.run(TUGIAssumingTransport.java:52)     在   org.apache.hadoop.hive.thrift.client.TUGIAssumingTransport $ 1.run(TUGIAssumingTransport.java:49)     在java.security.AccessController.doPrivileged(本机方法)在   javax.security.auth.Subject.doAs(来源未知)   org.apache.hadoop.security.UserGroupInformation.doAs(UserGroupInformation.java:1628)     在   org.apache.hadoop.hive.thrift.client.TUGIAssumingTransport.open(TUGIAssumingTransport.java:49)     在   org.apache.hive.jdbc.HiveConnection.openTransport(HiveConnection.java:203)     ...还有5个


JVM参数

-Djava.security.krb5.debug=true 
-Djava.security.krb5.conf="‪C:\Users\neverwinter\Desktop\krb5.conf"
-Djava.security.auth.login.config="C:\Users\neverwinter\Desktop\gss-jaas.conf"

我搜索了有关gss的信息,但没有任何帮助。我想念的是什么?任何想法都很棒。

0 个答案:

没有答案