gpt4 book ai didi

java - 从远程 HDFS 读取文件

转载 作者:可可西里 更新时间:2023-11-01 14:36:35 27 4
gpt4 key购买 nike

我正在尝试从远程 HDFS 系统读取文件并显示在本地计算机的控制台中。请注意,本地计算机只能通过 .pem 文件形式的 SSH key 与任何 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();
}

最佳答案

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

2) 输入hadoop dfsadmin -report检查 Missing blocks: 0

的值

关于java - 从远程 HDFS 读取文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40506257/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com