代码如下:
System.setProperty("java.security.krb5.conf", “/etc/krb5.conf");
Configuration conf = new Configuration();
conf.set("hadoop.security.authentication", "kerberos”);
// 将配置文件加载到conf
conf.addResource(hadoopConfDir);
// 设置hdfs,如果加载了hdfs-site,可以去掉下面配置
conf.set("fs.defaultFS", "hdfs://1.1.1.1:8020");
UserGroupInformation.setConfiguration(conf);
UserGroupInformation.loginUserFromKeytab("cz/cz@TEST.COM", "/tmp/cz/cz.keytab");
网友评论