在hadoop/hbase等代码中kinit

本文介绍了如何在Java代码中使用UserGroupInformation API进行Kerberos登录,并提供了具体代码示例。同时,针对kinit的超时问题,探讨了在长时间运行的程序(如storm)中如何通过定时刷新来保持认证有效,特别是在storm的Bolt中利用TickTuple实现定时任务的策略。
摘要由CSDN通过智能技术生成

在hadoop/hbase等代码中kinit

@(HBASE)[hadoop, hbase, storm, kafka]

(一)在java代码中kinit的方法

使用hadoop的UserGroupInformation
1、Set Kerberos login with the UserGroupInformation API:

import org.apache.hadoop.security.UserGroupInformation;
org.apache.hadoop.conf.Configuration conf = HBaseConfiguration.create();  
//注意,不能用set()等指定zk的方式。
conf.addResource("/path","hbase-site.xml");
conf.set("hadoop.security.authentication", "Kerberos");
UserGroupInformation.setConfiguration(conf);

2、Login with a keytab by calling the UserGroupInformation API:

UserGroupInformation.loginUserFromKeytab("example_user@netease.com", "/path/to/example_user.keytab");

完整代码:

public class HBaseKerberosDemo {

    public static void main(String[] args) throws Exception {

      
  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值