代码如下:
class KerberosAuth1 { def kerberosAuth(debug: Boolean): Unit = { try { System.setProperty("java.security.krb5.conf", "D:\\cdh\\spark\\src\\main\\kerberos\\krb5.conf") // System.setProperty("java.security.krb5.conf","/lvm/data3/zhc/krb5.conf"); System.setProperty("javax.security.auth.useSubjectCredsOnly", "false") if (debug) System.setProperty("sun.security.krb5.debug", "true") UserGroupInformation.loginUserFromKeytab("gree2@GREE.IO", "D:\\cdh\\spark\\src\\main\\kerberos\\gree2.keytab") // UserGroupInformation.loginUserFromKeytab("gree1@GREE.IO", "/lvm/data3/zhc/gree1.keytab"); System.out.println(UserGroupInformation.getCurrentUser) } catch { case e: Exception => e.printStackTrace() } } }main
object SparkTest { def main(args: Array[String]): Unit = { new KerberosAuth1().kerberosAuth(false); val sparkSession = SparkSession.builder().appName("spark2Test") // .config("spark.sql.warehouse.dir","/user/hive/warehouse") .master("local[*]").enableHiveSupport.getOrCreate() sparkSession.sql("select name from test.test").show() // sparkSession.sql("show tables").show() // sparkSession.sql("select name from default.linetest ").show() } }转载于:https://www.cnblogs.com/HarSenZhao/p/11510061.html
相关资源:数据结构—成绩单生成器