Hadoop身份验证与Kerberos错误

问题描述 投票:0回答:3

我正在尝试使用以下方法在HDFS中创建文件:

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;

为此我添加这样的配置:

Configuration configuration = new Configuration();

configuration.set("fs.hdfs.impl",
        org.apache.hadoop.hdfs.DistributedFileSystem.class.getName()
);
configuration.set("fs.file.impl",
        org.apache.hadoop.fs.LocalFileSystem.class.getName()
);

OutputStream fileout1 = new FileOutputStream("CONF_before.XML");
configuration.writeXml(fileout1);

configuration.addResource(new Path("/etc/hive/conf.cloudera.hive/hdfs-site.xml"));
configuration.addResource(new Path("/etc/hive/conf.cloudera.hive/core-site.xml"));
OutputStream fileout = new FileOutputStream("CONF_after.XML");
configuration.writeXml(fileout);
FileSystem hdfs = FileSystem.get(configuration);

Path out_path = new Path(hdfs.getWorkingDirectory() + "/OD.xml");
OutputStream os = hdfs.create(out_path);

当我运行此代码时,我在OutputStream os = hdfs.create(out_path)中收到错误:

Caused by: org.apache.hadoop.ipc.RemoteException(org.apache.hadoop.security.AccessControlException): SIMPLE authentication is not enabled.  Available:[TOKEN,KERBEROS]

但是如果我将core-site.xml添加到项目artefact并在服务器上运行它没有错误。

两种情况下的输出配置都相同。 core-site.xml的相关部分是:

 <property>
    <name>hadoop.security.authentication</name>
    <value>kerberos</value>
  </property>
  <property>
    <name>hadoop.security.authorization</name>
    <value>false</value>
  </property>
  <property>
    <name>hadoop.rpc.protection</name>
    <value>authentication</value>
  </property>

任何想法为什么会发生?谢谢!

java hadoop hdfs kerberos
3个回答
1
投票

尝试将此添加到hdfs-site.xml

<property>
  <name>ipc.client.fallback-to-simple-auth-allowed</name>
  <value>true</value>
</property>

0
投票

根据给定的错误消息RemoteException ... AccessControlException) ... SIMPLE authentication is not enabled. Available:[TOKEN,KERBEROS]和配置属性hadoop.security.authentication = kerberos,您似乎正在使用Kerberos安全集群,因此您的客户端访问HDFS不使用此配置并尝试进行简单的身份验证。


0
投票

我也遇到了这个问题,结果证明:

configuration.addResource(new Path("..."))

没有加载文件。

我没有跟踪原因,但我知道切换到接受InputStream的重载方法确实有效:

configuration.addResource(new FileInputStream(new File("...")))

您写道,如果将XML添加到JAR资源中可以解决问题 - 这是因为默认情况下,Configuration类在类路径中查找两个XML文件并尝试加载它们。为了快速参考,Configuration类实现的一个片段:

addDefaultResource("core-default.xml");
addDefaultResource("core-site.xml");
© www.soinside.com 2019 - 2024. All rights reserved.