在hadoop/hbase等代码中kinit
生活随笔
收集整理的這篇文章主要介紹了
在hadoop/hbase等代码中kinit
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
在hadoop/hbase等代碼中kinit
@(HBASE)[hadoop, hbase, storm, kafka]
(一)在java代碼中kinit的方法
使用hadoop的UserGroupInformation
1、Set Kerberos login with the UserGroupInformation API:
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()方法中添加以下代碼。
總結
以上是生活随笔為你收集整理的在hadoop/hbase等代码中kinit的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: HBase 1.x Coprocesso
- 下一篇: Hadoop使用MultipleOutp