0

大家好,我正在研究 hadoop,并且我配置了 2 个节点的 hadoop 集群。我必须使用 java 代码在 hadoop 文件系统中创建目录,但是每次运行此代码时都会遇到一些异常。

我的java代码

import java.io.IOException;

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

public class Hadoopjava {

    public static void main(String ar[]) throws IOException

    {

        Configuration conf = new Configuration();

        /*conf.addResource(new Path("core-site.xml"));
        conf.addResource(new Path("hdfs-site.xml"));*/
            conf.set("fs.default.name", "hdfs://master:54310");


        String dirName = "dd";

        //values of hosthdfs:port can be found in the core-site.xml  in the fs.default.name

        FileSystem fileSystem = FileSystem.get(conf);

        Path path = new Path("/user/hduser/dd/gg");
        fileSystem.mkdirs(path) ; 

       // System.out.println(data);
        /*Path path = new Path("/user/hduser/dd");
        if (fileSystem.exists(path)) {
            System.out.println("Dir " + dirName + " already exists");
            return;
        }

        // Create directories
        fileSystem.mkdirs(path);*/

        fileSystem.close();
    }
}

我的代码中的异常

Exception in thread "main" java.io.IOException: Call to master/192.168.0.128:54310 failed on local exception: java.io.EOFException
    at org.apache.hadoop.ipc.Client.wrapException(Client.java:775)
    at org.apache.hadoop.ipc.Client.call(Client.java:743)
    at org.apache.hadoop.ipc.RPC$Invoker.invoke(RPC.java:220)
    at sun.proxy.$Proxy0.getProtocolVersion(Unknown Source)
    at org.apache.hadoop.ipc.RPC.getProxy(RPC.java:359)
    at org.apache.hadoop.hdfs.DFSClient.createRPCNamenode(DFSClient.java:106)
    at org.apache.hadoop.hdfs.DFSClient.<init>(DFSClient.java:207)
    at org.apache.hadoop.hdfs.DFSClient.<init>(DFSClient.java:170)
    at org.apache.hadoop.hdfs.DistributedFileSystem.initialize(DistributedFileSystem.java:82)
    at org.apache.hadoop.fs.FileSystem.createFileSystem(FileSystem.java:1378)
    at org.apache.hadoop.fs.FileSystem.access$200(FileSystem.java:66)
    at org.apache.hadoop.fs.FileSystem$Cache.get(FileSystem.java:1390)
    at org.apache.hadoop.fs.FileSystem.get(FileSystem.java:196)
    at org.apache.hadoop.fs.FileSystem.get(FileSystem.java:95)
    at com.widevision.hadoop.Hadoopjava.main(Hadoopjava.java:26)
Caused by: java.io.EOFException
    at java.io.DataInputStream.readInt(DataInputStream.java:392)
    at org.apache.hadoop.ipc.Client$Connection.receiveResponse(Client.java:501)
    at org.apache.hadoop.ipc.Client$Connection.run(Client.java:446)

我正在为 java 代码使用 eclipse IDE。

我的代码有什么问题???

4

1 回答 1

1

请确保您正在针对您在集群上运行的相同 Hadoop 版本编译代码。看起来像是不同协议版本之间的协议不匹配。

于 2013-09-27T12:01:11.053 回答