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>    
    

      

  • 相关阅读:
    C++ #include .h extern 的相关关系及说明
    VC++ list函数详解
    VC++ 限制窗口的大小范围的方法
    VC++ CTreeCtrl 使用NM_CLICK和TVN_SELCHANGED
    Vc++ 控件用法总结之List Control
    VC++ 将IP字符串转为 DWORD值
    C语言提供了几个标准库函数 itoa() atoi()
    C语言 malloc calloc realloc alloc 在分配内存时的 区别
    C语言 malloc、calloc、realloc的区别
    VC++ MFC中如何将应用程序的配置信息保存到注册表中(二)
  • 原文地址:https://www.cnblogs.com/BigWrite/p/13530991.html
Copyright © 2011-2022 走看看