hbase等代码中kinit
来源:互联网 发布:正版办公软件要买吗 编辑:程序博客网 时间:2024/05/20 05:26
在hadoop/hbase等代码中kinit
@(博客文章)[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("example_user@netease.com", "/path/to/example_user.keytab"); } catch (IOException e) { e.printStackTrace(); }
0 0
- hbase等代码中kinit
- 在hadoop/hbase等代码中kinit
- How to kinit hbase user
- kinit manual
- kinit -f
- 在IDEA14中使用代码连接Hbase
- VS中代码对齐等快捷键【转】
- VS中代码对齐等快捷键
- 代码中添加drawableLeft/drawableRight等
- LaTeX中图形表格等格式代码
- VS中代码对齐等快捷键
- HBase replication 代码分析
- hbase测试 java代码
- hbase 分页代码
- Hbase代码优化总结
- C++读写HBase代码
- hbase的hbase-site.xml配置文件代码
- 使用某个用户登录命令:kinit adminad
- commons-digester
- 转载---TCP/IP序列号和确认号详解
- 53. Maximum Subarray
- HDU 1541 Stars
- 在ROS下写Hello ROS!
- hbase等代码中kinit
- POJ 2991 Crane 线段树
- Erlang分布式编程
- Android_Back键再按一次退出程序
- 记录一下mysql的递归。。
- Java8函数式编程实现一个工厂
- activity和service之间的相互通信方法
- Android事件分发机制,事件拦截和事件响应
- 自定义实现MPVolumeView音量控件