Java 带有Kerberos错误的Hadoop身份验证

Java 带有Kerberos错误的Hadoop身份验证,java,hadoop,hdfs,kerberos,Java,Hadoop,Hdfs,Kerberos,我正在尝试使用以下方式在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",

我正在尝试使用以下方式在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\u path)
中得到一个错误:

但是,如果我将
core site.xml
添加到项目人工制品中并在服务器上运行它,则不会出现错误

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

hadoop.security.authentication
kerberos
hadoop.security.authorization
假的
hadoop.rpc.protection
认证
知道为什么会这样吗?
谢谢

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

configuration.addResource(new Path("..."))
没有加载该文件

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

configuration.addResource(new FileInputStream(new File("...")))
您写道,如果将XML添加到JAR资源中,则可以解决此问题—这是因为默认情况下,
Configuration
class在类路径中查找两个XML文件并尝试加载它们。为便于快速参考,请参阅
配置
类实现的一部分:

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

根据给定的错误消息
RemoteException。。。AccessControlException)。。。未启用简单身份验证。可用:[令牌,KERBEROS]
和配置属性
hadoop.security.authentication=KERBEROS
您似乎正在使用KERBEROS安全群集,因此您访问HDFS的客户端没有使用此配置并尝试执行简单的身份验证

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


ipc.client.fallback-to-simple-auth-allowed
真的

谢谢,这是个健康的主意。但这对我没有帮助。我需要配置kerberos票证吗?您收到的错误指向属性
hadoop.security.authentication
未设置为
kerberos
-就像您的配置未加载一样。加载配置资源后打印出此属性并检查其值。因此,加载配置后的输出参数是ok(kerberos)。
addDefaultResource("core-default.xml");
addDefaultResource("core-site.xml");