zoukankan      html  css  js  c++  java
  • java 通过jdbc 连接hive2 使用kerberos 认证

    hadoop version:3.1

    private static Connection initConn(String hive_driverName, String krb5FilePath, String krb5KeyTabPath, String krbPrincipal, String userName, String url) throws SQLException, IOException, ClassNotFoundException {
            System.setProperty("java.security.krb5.conf", krb5FilePath);
            System.setProperty("sun.security.krb5.debug", "true");
            // 解决windows中执行可能出现找不到HADOOP_HOME或hadoop.home.dir问题
            // Kerberos认证
            org.apache.hadoop.conf.Configuration configuration = new org.apache.hadoop.conf.Configuration();
            configuration.set("hadoop.security.authentication", "Kerberos");
            configuration.set("keytab.file", krb5KeyTabPath);
            configuration.set("kerberos.principal", krbPrincipal);
            UserGroupInformation.setConfiguration(configuration);
            UserGroupInformation.loginUserFromKeytab(userName, krb5KeyTabPath);
    
            // 创建hive连接
            Class.forName(hive_driverName);
            Connection connection = DriverManager.getConnection(url);
            if (connection == null) {
                throw new NullPointerException("获取connection失败");
            }
            return connection;
        }
    

      一般报 Can't get Kerberos realm 错误是因为,找不到 krb5.conf文件路径

    pom依赖

            <!--hive连接-->
            <dependency>
                <groupId>org.apache.hadoop</groupId>
                <artifactId>hadoop-common</artifactId>
                <version>3.2.0</version>
                <exclusions>
                    <exclusion>
                        <groupId>jdk.tools</groupId>
                        <artifactId>jdk.tools</artifactId>
                    </exclusion>
                </exclusions>
            </dependency>
            <dependency>
                <groupId>org.apache.hive</groupId>
                <artifactId>hive-jdbc</artifactId>
                <version>3.1.2</version>
                <exclusions>
                    <exclusion>
                        <groupId>org.eclipse.jetty</groupId>
                        <artifactId>*</artifactId>
                    </exclusion>
                </exclusions>
            </dependency>    
    

      阿里云镜像

            <repository>
                <id>aliyun</id>
                <name>aliyun</name>
                <url>http://maven.aliyun.com/nexus/content/groups/public/</url>
            </repository>    
    

      

  • 相关阅读:
    6.无监督学习-降维
    5.无监督学习-DBSCAN聚类算法及应用
    4.无监督学习--K-means聚类
    如何让虚拟机与本机进行通信
    Linux网络配置
    网关是什么?有什么作用?
    DNS是什么
    软件工程第四周作业代码规范
    软件工程第四周作业之四则运算-C#实现
    一些讨论、读书的感想
  • 原文地址:https://www.cnblogs.com/BigWrite/p/13530991.html
Copyright © 2011-2022 走看看