使用python和Kerberos连接到配置单元

2024-06-16 13:32:23 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试使用Python连接到hive。我安装了所需的所有依赖项(sasl、thrift\u sasl等)

以下是我尝试连接的方式:

configuration = {"hive.server2.authentication.kerberos.principal" : "hive/_HOST@REALM_HOST", "hive.server2.authentication.kerberos.keytab" : "/etc/security/keytabs/hive.service.keytab"}

connection = hive.Connection(configuration = configuration, host="host", port=port, auth="KERBEROS", kerberos_service_name = "hiveserver2")

但我得到一个错误:

Minor code may provide more information (Cannot find KDC for realm "REALM_DOMAIN")

我错过了什么?有人有没有使用kerberospyHive连接的例子?在

谢谢你的帮助。在


Tags: principalhostauthenticationportservice方式kerberosthrift
2条回答

谢谢你@Kishore。 实际上在PySpark中,代码如下所示:

import pyspark
from pyspark import SparkContext
from pyspark.sql import Row
from pyspark import SparkConf
from pyspark.sql import HiveContext
from pyspark.sql import functions as F
import pyspark.sql.types as T

def connection(self):
    conf = pyspark.SparkConf()
    conf.setMaster('yarn-client')
    sc = pyspark.SparkContext(conf=conf)

    self.cursor = HiveContext(sc)

    self.cursor.setConf("hive.exec.dynamic.partition", "true")
    self.cursor.setConf("hive.exec.dynamic.partition.mode", "nonstrict")
    self.cursor.setConf("hive.warehouse.subdir.inherit.perms", "true")
    self.cursor.setConf('spark.scheduler.mode', 'FAIR')

您可以使用以下方式请求:

^{pr2}$

我实际上是通过命令运行代码:

spark-submit  master yarn MyProgram.py

我想您可以使用基本上运行安装了pyspark的python,如下所示:

python MyProgram.py 

但我没试过,所以我不能保证它是有效的

我不知道pyspark,但我使用的是scala下面的代码,它从去年开始工作。如果您可以在python中更改此代码。替换基于kerberos的属性值。在

System.setProperty("hive.metastore.uris", "add hive.metastore.uris url");
System.setProperty("hive.metastore.sasl.enabled", "true")
System.setProperty("hive.metastore.kerberos.keytab.file", "add keytab")
System.setProperty("hive.security.authorization.enabled", "false")
System.setProperty("hive.metastore.kerberos.principal", "replace hive.metastore.kerberos.principal value")
System.setProperty("hive.metastore.execute.setugi", "true")
val hiveContext = new HiveContext(sparkContext)

相关问题 更多 >