如何在Java应用程序中的不同hadoop集群之间传输数据?

时间:2013-08-21 06:04:56

标签: hadoop

我的示例java应用程序是从一个hadoop集群读取数据并将其存储在另一个hadoop集群中(比如A,B)。

这是从A中读取数据的示例代码。

    StringBuilder result=new StringBuilder();
    Configuration conf = new Configuration();
    FileSystem fs = FileSystem.get(conf);
    FileStatus[] status=fs.listStatus(new Path("/result/test1"));
    for(FileStatus file:status){
        System.out.println(file.getPath().toString());
        if(file.getPath().toString().contains("part")){
            FSDataInputStream inputStream=fs.open(file.getPath());
            String inputString;
            while((inputString=inputStream.readLine())!=null){
                result.append(inputString);
            }
        }
    }

下面的代码是访问B

    conf.set("fs.default.name", "hdfs://10.101.51.221:9000");
    conf.set("mapred.job.tracker", "hdfs://10.101.51.221:9001");
    fs=FileSystem.get(conf);

此示例java应用程序在其构建路径中包含A的hadoop / conf / *以访问A,我想我也可以通过更改fs.default.name和mapred.job.tracker来访问B,但它不会工作。错误消息就像

13/08/21 14:41:08 INFO ipc.Client: Retrying connect to server: Already tried 0 time(s).
...
13/08/21 14:41:26 INFO ipc.Client: Retrying connect to server: Already tried 9 time(s).
Exception in thread "main" java.net.ConnectException: Call to server failed on connection exception: java.net.ConnectException: Connection refused: no further information

有关此问题的任何提示都将不胜感激

1 个答案:

答案 0 :(得分:0)

DistCp(分布式副本)是一种用于大型群集间/群集内复制的工具。

  • bash $ hadoop distcp hdfs:// src:8020 / foo / bar hdfs:// dest:8020 / bar / foo

http://hadoop.apache.org/docs/stable/distcp.html#cpver

在java应用程序中,您可以使用 org.apache.hadoop.tools.DistCp

相关问题