【发布时间】:2020-07-01 04:15:54
【问题描述】:
我正在尝试在本地使用 Scala 和 Apache Spark 来查询由 Kerberos 保护的 Hive 表。在没有 Spark 的情况下,以编程方式连接和查询数据没有任何问题。但是,当我尝试在 Spark 中连接和查询时,问题就来了。
我的代码在本地运行时没有火花:
Class.forName("org.apache.hive.jdbc.HiveDriver")
System.setProperty("kerberos.keytab", keytab)
System.setProperty("kerberos.principal", keytab)
System.setProperty("java.security.krb5.conf", krb5.conf)
System.setProperty("java.security.auth.login.config", jaas.conf)
val conf = new Configuration
conf.set("hadoop.security.authentication", "Kerberos")
UserGroupInformation.setConfiguration(conf)
UserGroupInformation.createProxyUser("user", UserGroupInformation.getLoginUser)
UserGroupInformation.loginUserFromKeytab(user, keytab)
UserGroupInformation.getLoginUser.checkTGTAndReloginFromKeytab()
if (UserGroupInformation.isLoginKeytabBased) {
UserGroupInformation.getLoginUser.reloginFromKeytab()
}
else if (UserGroupInformation.isLoginTicketBased) UserGroupInformation.getLoginUser.reloginFromTicketCache()
val con = DriverManager.getConnection("jdbc:hive://hdpe-hive.company.com:10000", user, password)
val ps = con.prepareStatement("select * from table limit 5").executeQuery();
有谁知道我如何将 keytab、krb5.conf 和 jaas.conf 包含到我的 Spark 初始化函数中,以便我能够通过 Kerberos 进行身份验证以获取 TGT?
我的 Spark 初始化函数:
conf = new SparkConf().setAppName("mediumData")
.setMaster(numCores)
.set("spark.driver.host", "localhost")
.set("spark.ui.enabled","true") //enable spark UI
.set("spark.sql.shuffle.partitions",defaultPartitions)
sparkSession = SparkSession.builder.config(conf).enableHiveSupport().getOrCreate()
我没有 hive-site.xml、core-site.xml 等文件。
谢谢!
【问题讨论】:
标签: apache-spark hive apache-spark-sql kerberos