【问题标题】:Hadoop authentication with Kerberos error带有 Kerberos 错误的 Hadoop 身份验证
【发布时间】:2018-04-26 13:21:27
【问题描述】:

我正在尝试使用以下方法在 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 添加到项目工件并在服务器上运行它,则不会出现错误。

两种情况下的输出配置相同。 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


    【解决方案1】:

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

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

    【讨论】:

      【解决方案2】:

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

      【讨论】:

        【解决方案3】:

        我也遇到过这个问题,结果是:

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

        没有加载文件。

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

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

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

        addDefaultResource("core-default.xml");
        addDefaultResource("core-site.xml");
        

        【讨论】:

        • 谢谢,这是一个健康的想法。但这对我没有帮助。我需要配置 kerberos 票证吗?
        • 您收到的错误指出属性hadoop.security.authentication 未设置为kerberos - 就像您的配置未加载一样。加载配置资源后打印出该属性并检查其值。
        • 所以,加载配置后的out参数是ok的(kerberos)。
        猜你喜欢
        • 2015-05-23
        • 2011-04-12
        • 2018-07-06
        • 1970-01-01
        • 1970-01-01
        • 2016-11-08
        • 2015-06-22
        • 1970-01-01
        相关资源
        最近更新 更多