通过keytab的方式访问HDFS
Configuration config = new Configuration();
FileSystem hdfs = null;
try {
if (isKerberosEnable){
System.setProperty("java.security.krb5.conf", "./config/kerberos/krb5.conf");
config.set("hadoop.security.authentication","kerberos");
config.addResource("./config/cluster/hadoop/core-site.xml");
config.addResource("./config/cluster/hadoop/hdfs-site.xml");
UserGroupInformation.setConfiguration(config);
UserGroupInformation.loginUserFromKeytab(kerberosLoginUser, "./config/kerberos/hdfs.keytab");
UserGroupInformation userGroupInformation = UserGroupInformation.getLoginUser();
}
hdfs = FileSystem.get(URI.create(hdfsUri), config);
FSDataOutputStream outputStream = hdfs.cre