【问题标题】:Reading file from a remote HDFS从远程 HDFS 读取文件
【发布时间】:2016-11-09 11:47:26
【问题描述】:

我正在尝试从远程 HDFS 系统读取文件并显示在本地计算机的控制台中。请注意,本地机器只能通过 .pem 文件形式的 SSH 密钥与任何 HDFS 节点建立连接。

当我执行下面显示的一段代码时,程序运行,保持空闲一段时间,最后显示:

BlockMissingException : Could not obtain block

我的代码:

try {
            UserGroupInformation ugi = UserGroupInformation.createRemoteUser("remoteUser");

            ugi.doAs(new PrivilegedExceptionAction<Void>() {
                public Void run() throws Exception {
                    conf = new Configuration();
                    conf.set("fs.hdfs.impl", org.apache.hadoop.hdfs.DistributedFileSystem.class.getName());
                    conf.set("fs.file.impl", org.apache.hadoop.fs.LocalFileSystem.class.getName());
                    conf.addResource(new Path("/etc/hadoop/conf/core-site.xml"));
                    conf.addResource(new Path("/etc/hadoop/conf/hdfs-site.xml"));
                    conf.addResource(new Path("/etc/hadoop/conf/mapred-site.xml"));
                    conf.set("fs.default.name", hdfsurl);
                    conf.set("fs.defaultFS", hdfsurl);
                    conf.set("hadoop.job.ugi", "remoteUser");
                    conf.set("hadoop.ssl.enabled", "false");
                    readFromHDFS(hdfsurl);
                    return null;
                }
            });
        } catch (Exception e) {



public static void readFromHDFS(String hdfsURL) throws Exception {
        FileSystem fileSystem = FileSystem.get(conf);
        Path path = new Path(hdfsURL);
        if (!fileSystem.exists(path)) {
            System.out.println("File does not exists");
            return;
        }
        FSDataInputStream in = fileSystem.open(path);
        Scanner sc = new Scanner(in);
        while (sc.hasNextLine()) {
            System.out.println("line read from hdfs...." + sc.nextLine());
        }
        in.close();
        fileSystem.close();
}

【问题讨论】:

    标签: java hadoop hdfs remote-access readfile


    【解决方案1】:

    1) 输入hadoop fsck HDFS_FILE 检查特定的 hdfs 文件是否健康 如果不是,则特定文件已损坏。删除损坏的文件并尝试以下命令

    2) 输入hadoop dfsadmin -report 检查Missing blocks: 0的值是否

    【讨论】:

    • 好。我觉得应该尝试使用 Hadoop Admin 命令来调试此类问题
    • 谢谢尼尔马尔拉姆。但我检查了,文件的状态只是健康。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-10-01
    • 2021-06-18
    • 2015-05-11
    相关资源
    最近更新 更多