python kerberos hbase_带有Kerberos的HBase - 保持一个HTable实例打开超过10个小时

Here is the situation: we have a secured (Kerberos) HBase cluster.

I have an object that creates an instance of HTable at startup and hang on to it. It calls:

UserGroupInformation.setConfiguration(configuration);

UserGroupInformation.loginUserFromKeytab(user, keytab);

to login to the Kerberized cluster.

This object then hangs around unused for many hours. After more than 10 hours (the timeout on a ticket from our Kerberos cluster), the next call to scan the table results in this:

16/12/01 18:16:24 WARN security.UserGroupInformation: PriviledgedActionException as:bigdata-app-analyticscore-msr@INTQA.THOMSONREUTERS.COM (auth:KERBEROS) cause:javax.security.sasl.SaslException: GSS initiate failed [Caused by GSSException: No valid credentials provided (Mechanism level: Failed to find any Kerberos tgt)]

16/12/01 18:16:24 WARN ipc.RpcClient: Exception encountered while connecting to the server : javax.security.sasl.SaslException: GSS initiate failed [Caused by GSSException: No valid credentials provided (Mechanism level: Failed to find any Kerberos tgt)]

16/12/01 18:16:24 FATAL ipc.RpcClient: SASL authentication failed. The most likely cause is missing or invalid credentials. Consider 'kinit'.

- javax.security.sasl.SaslException: GSS initiate failed [Caused by GSSException: No valid credentials provided (Mechanism level: Failed to find any Kerberos tgt)]

- at com.sun.security.sasl.gsskerb.GssKrb5Client.evaluateChallenge(GssKrb5Client.java:211)

- etc.

How can I keep the Kerberos authentication alive?

解决方案

I happened to be doing some research in this forum earlier. The problem statement here, where Kerberos authentication dies after 10 hours, is nearly identical to that of this thread:

I actually just edited that thread earlier today and placed the "10 hours" into the Subject line. That thread contains some great advice on what to do here. I'm going to go ahead and borrow the good wisdom provided by Samson Scharfrichter who stated in it: "The standard solution is to spawn a background thread invoking checkTGTAndReloginFromKeytab() periodically -- see Should I call ugi.checkTGTAndReloginFromKeytab() before every action on hadoop? for a very elaborate explanation by a HortonWorks guru (a colleague of the guy who wrote that GitBook about Hadoop & Kerberos)"

I hope this provides your direction.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
在 Scala 中使用 HBaseKerberos 进行身份验证需要进行以下步骤: 1. 配置 Kerberos:首先,确保 HBase 集群已经启用了 Kerberos 身份验证。您需要获取正确的 Kerberos Principal(主体)和 Keytab(密钥表)文件。 2. 添加 HBaseKerberos依赖:在 Scala项目的构建文件(例如 build.sbt)中添加必要的依赖项。例如,您可以添加以下依赖项: ```scalalibraryDependencies += "org.apache.hbase" % "hbase-client" % "版本号" libraryDependencies += "org.apache.hadoop" % "hadoop-auth" % "版本号" ``` 请确保将版本号替换为您正在使用的 HBase 和 Hadoop 版本。 3. 创建 HBase 配置:在 Scala代码中,您需要创建一个 HBase 配置对象,并设置相应的属性,以使用 Kerberos 进行身份验证。例如: ```scalaimport org.apache.hadoop.conf.Configurationimport org.apache.hadoop.security.UserGroupInformationval conf = HBaseConfiguration.create() conf.set("hbase.zookeeper.quorum", "zkQuorum") conf.set("hbase.zookeeper.property.clientPort", "zkPort") conf.set("zookeeper.znode.parent", "/hbase") conf.set("hadoop.security.authentication", "kerberos") // 设置 Kerberos Principal 和 Keytab 文件路径val krbPrincipal = "your_kerberos_principal" val krbKeytab = "path_to_your_keytab_file" System.setProperty("java.security.krb5.conf", "/etc/krb5.conf") UserGroupInformation.setConfiguration(conf) UserGroupInformation.loginUserFromKeytab(krbPrincipal, krbKeytab) ``` 请确保将 "zkQuorum" 和 "zkPort" 替换为您的 ZooKeeper 地址和端口。 4. 使用 HBase 进行操作:现在,您可以使用 Scala 和 HBase 客户端库进行各种操作,例如读取和写入数据。根据您的需求,使用适当的 HBase API 进行操作。 请注意,这只是一个简单的示例,您可能需要针对您的特定环境和需求进行更多的配置和调整。 希望这可以帮助您在 Scala 中使用 HBaseKerberos 进行身份验证!如果您有任何进一步的问题,请随时提问。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值