java - 无法连接Hadoop

标签 java hadoop hdfs

连接到hadoop时,出现以下错误

线程“主”中的异常java.lang.AbstractMethodError:org.apache.hadoop.hdfs.server.namenode.ha.ConfiguredFailoverProxyProvider.getProxy()Lorg / apache / hadoop / io / retry / FailoverProxyProvider $ ProxyInfo;
在org.apache.hadoop.io.retry.RetryInvocationHandler。(RetryInvocationHandler.java:73)
在org.apache.hadoop.io.retry.RetryInvocationHandler。(RetryInvocationHandler.java:64)
在org.apache.hadoop.io.retry.RetryProxy.create(RetryProxy.java:58)
在org.apache.hadoop.hdfs.NameNodeProxies.createProxy(NameNodeProxies.java:147)
在org.apache.hadoop.hdfs.DFSClient。(DFSClient.java:510)
在org.apache.hadoop.hdfs.DFSClient。(DFSClient.java:453)
在org.apache.hadoop.hdfs.DistributedFileSystem.initialize(DistributedFileSystem.java:136)
在org.apache.hadoop.fs.FileSystem.createFileSystem(FileSystem.java:2653)
在org.apache.hadoop.fs.FileSystem.access $ 200(FileSystem.java:92)
在org.apache.hadoop.fs.FileSystem $ Cache.getInternal(FileSystem.java:2687)
在org.apache.hadoop.fs.FileSystem $ Cache.get(FileSystem.java:2669)
在org.apache.hadoop.fs.FileSystem.get(FileSystem.java:371)
在org.apache.hadoop.fs.FileSystem.get(FileSystem.java:170)
在hrumen.HTest.main(HTest.java:26)

下面是我的代码:

***Path corepath = new Path("/var/tmp/hactive/core-site.xml");
        Path sitepath = new Path("/var/tmp/hactive/hdfs-site.xml");
        Path yarnpath = new Path("/var/tmp/hactive/yarn-site.xml");
        Path mapredpath = new Path("/var/tmp/hactive/mapred-site.xml");

        Configuration hconf = new Configuration();
        hconf.addResource(corepath);
        hconf.addResource(sitepath);
        hconf.addResource(yarnpath);
        hconf.addResource(mapredpath);

        try{
            DFSAdmin dfadmin = new DFSAdmin(hconf);
            dfadmin.report();

        }
        catch(Exception e){
            //System.out.println("[Exception]: "+e);
            e.printStackTrace();
        }***

这里是hdfs-site.xml的一部分
...
    <property>
        <name>dfs.nameservices</name>
        <value>mycluster</value>
        <final>true</final>

    </property>
....

    <property>
        <name>dfs.client.failover.proxy.provider.mycluster</name>
        <value>org.apache.hadoop.hdfs.server.namenode.ha.ConfiguredFailoverProxyProvider</value>
    </property>

在core-site.xml中
<property>
    <name>fs.defaultFS</name>
    <value>hdfs://mycluster</value>
</property>

....

最佳答案

尝试运行我的应用程序时(在Hortonworks中),我遇到了同样的问题。卡住之后-花了一段时间,因此在此处添加以供将来引用-以下内容解决了该问题。

要么添加到 pom.xml (注意:版本可能有所不同,请相应设置):

<dependency>
   <groupId>org.apache.hadoop</groupId>
   <artifactId>hadoop-hdfs</artifactId>
   <version>2.8.1</version>
</dependency>

或添加:
/path/to/hadoop-hdfs-client-<version_number>.jar

到您的类路径中,以便在运行时包含 hadoop-hdfs-client jar。

关于java - 无法连接Hadoop,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47195693/

相关文章:

java - 压缩 Android AudioRecord.read(byte[], int, int) 返回的原始数据

用于检测类/接口(interface)/等声明的 Java 正则表达式

java - 构建键值存储

hadoop - 快速HDFS和Hive数据复制

java - 方案 : webhdfs 没有文件系统

java - 如何调用少参数的存储过程?

performance - Spark : Inconsistent performance number in scaling number of cores

hadoop - Hive 0.14.0 未启动

web-services - Hadoop前面的服务

java - 在spark java api中递归地从HDFS读取所有文件