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>    
    

      

  • 相关阅读:
    GyPSii API PHP应用初探
    无缝滚动图片的一个简单封装
    Linux设置固定IP
    DIV卷帘效果示例
    vsftp安装配置
    PHP判断FORM来的数据是否为整数
    Linux下设置apache开机启动
    从Discuz提取的数据库和模板操作文件,很容易使用哦
    discuz 表情的提取
    IE6、IE7浮动层被下面的动挡住的问题
  • 原文地址:https://www.cnblogs.com/BigWrite/p/13530991.html
Copyright © 2011-2022 走看看