java jdbc连接kerberos认证hive

hive 集成kerber后,jdbc连接操作hive

public static void main(String[] args) throws Exception {
        System.setProperty("java.security.krb5.conf", "E:\\conf\\xh\\local\\krb5.conf");
        Configuration config = new Configuration();
        UserGroupInformation.setConfiguration(config);
        UserGroupInformation.loginUserFromKeytab("hive/[email protected]", "E:\\conf\\xh\\local\\hive.keytab");

        String driver = "org.apache.hive.jdbc.HiveDriver";
        String jdbc = "jdbc:hive2://master:10000/default;principal=hive/[email protected]";
        String user = "hive";
        String pass = "hive";

        Class.forName(driver);
        Connection connection = DriverManager.getConnection(jdbc, user, pass);
    }

认证错误:
1.

Error: Could not open client transport with JDBC Uri: jdbc:hive2://master:10000/default: Peer indicated failure: Unsupported mechanism type PLAIN (state=08S01,code=0)
//解决: jdbc连接url时,缺少principal,整个url连接如下:
jdbc:hive2://master:10000/default;principal=hive/master@HADOOP.COM
Error: Could not open client transport with JDBC Uri: jdbc:hive2://master:10000/default;principal=hdfs/[email protected]: Peer indicated failure: GSS initiate failed (state=08S01,code=0)
//解决: jdbc连接url时,principal的用户有问题,整个url连接如下:
principal=hdfs/master@HADOOP.COM 替换为:hive/master@HADOOP.COM
jdbc:hive2://master:10000/default;principal=hive/master@HADOOP.COM

你可能感兴趣的:(hadoop)