在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 {