【问题标题】:how to transfer data between different hadoop clusters in Java application?如何在 Java 应用程序中的不同 hadoop 集群之间传输数据?
【发布时间】:2013-08-21 22:17:17
【问题描述】:

我的示例 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

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

【问题讨论】:

    标签: hadoop


    【解决方案1】:

    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

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-07-09
    • 2018-03-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多