在hadoop/hbase等代码中kinit
来源:互联网 发布:做三维动画的软件 编辑:程序博客网 时间:2024/06/06 03:54
在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 { Configuration conf = HBaseConfiguration.create(); //注意,不能用set()等指定zk的方式。 conf.addResource("/path","hbase-site.xml"); conf.set("hadoop.security.authentication", "Kerberos"); UserGroupInformation.setConfiguration(conf); UserGroupInformation.loginUserFromKeytab(args[0], args[1]); Connection connection = ConnectionFactory.createConnection(conf); Table tbl = connection.getTable(TableName.valueOf(args[2])); Put put = new Put(Bytes.toBytes("r1")); put.addColumn(Bytes.toBytes("f1"), Bytes.toBytes("c1"), Bytes.toBytes("v1")); tbl.put(put); tbl.close(); connection.close(); } }
(二)定时刷新
kinit会有超时时间,如果程序需要长时间运行,则需要定时去刷新一下,可以通过一个线程来实现。
这种应用场景常见于storm,在storm中提供了TickTuple来实现这种定时功能。
事实证明不需要定时refresh的,在storm需要操作hbase的bolt的prepare()方法中添加以下代码。
Configuration config = HBaseConfiguration.create(); //根据实际路径设置,也可以使用逐个参数添加的方式,但建议使用系统的hbase-site.xml。 config.addResource(new Path("/home/hadoop/conf/hbase", "hbase-site.xml")); config.set("hadoop.security.authentication", "Kerberos"); UserGroupInformation.setConfiguration(config); try { UserGroupInformation.loginUserFromKeytab("g18_us/scheduler", "/home/hadoop/keytab/g18_us.keytab"); } catch (IOException e) { e.printStackTrace(); }
阅读全文
0 0
- 在hadoop/hbase等代码中kinit
- hbase等代码中kinit
- How to kinit hbase user
- 在IDEA14中使用代码连接Hbase
- 我在hadoop+zookeeper+hbase配置中出现的错误
- 在Hadoop上安装HBase
- hadoop、hbase、hive等版本对应关系
- hadoop中在map和reduce方法中调试代码
- hadoop、zookeeper、hbase在Linux中的安装
- 什么是Zookeeper,Zookeeper的作用是什么,在Hadoop及hbase中具体作用是什么
- 什么是Zookeeper,Zookeeper的作用是什么,在Hadoop及hbase中具体作用是什么
- 建立HBase的集群和HDInsight在Hadoop中使用Hive来查询它们
- 什么是Zookeeper,Zookeeper的作用是什么,在Hadoop及hbase中具体作用是什么
- 什么是Zookeeper,Zookeeper的作用是什么,在Hadoop及hbase中具体作用是什么
- 什么是Zookeeper,Zookeeper的作用是什么,在Hadoop及hbase中具体作用是什么
- 什么是Zookeeper,Zookeeper的作用是什么,在Hadoop及hbase中具体作用是什么
- hadoop zookeeper hive hbase kylin等的部署
- hadoop 中MapReduce代码运行在win7上(本地)
- java 通过map的value返回其对应的key (遍历map)
- docker实践——从新镜像启动容器报错解决
- 在tomcat中部署了grails项目报错:IllegalArgumentException occurred when processing request
- java获取计算机cpu型号
- KindEditor编辑器的使用
- 在hadoop/hbase等代码中kinit
- Excel一键导SQL插件
- 广场舞--2016蓝桥杯 国赛 JAVA A组 第5题
- 从内核驱动到android app
- 设置进程的显示名称
- 关于VM tools安装小结
- github版本回退--GitHub教程
- Android 添加权限一览表
- powerdesign使用