【发布时间】:2020-01-15 18:54:16
【问题描述】:
我的var/log/hadoop-hdfs/hdfs-audit.log 位于本地名称节点上,并由head /var/log/hadoop-hdfs/hdfs-audit.log 访问。我的数据文件由hdfs dfs -ls / 访问,而审计文件可以被cd 到。现在我可以在 java 中访问我的 hdfs 文件,但每次我尝试 fs.getLocal(conf) 时,conf 由 conf.set(FileSystem.FS_DEFAULT_NAME_KEY, namenode) 设置,我会在我的计算机上获取本地文件,而不是 namenode 上的本地文件。
下面的工作是获取data下的所有文件和目录。
public class HdfsAuditLogParser {
private final String cluster;
private final FileSystem fs;
public HdfsAuditLogParser(String cluster, String namenode) throws IOException {
this.cluster = cluster;
Configuration conf = new Configuration();
conf.set(FileSystem.FS_DEFAULT_NAME_KEY, namenode);
this.fs = FileSystem.get(conf);
}
public String parse() throws IOException {
for (FileStatus f : fs.listStatus(new Path("/data/"))){
System.out.println(f.getPath().toString());
}
return "output";
}
}
但是如果我将 /data/ 更改为 /var/log/,它就不起作用了,我什至尝试切换 this.fs = FileSystem.getLocal(conf); 但这不起作用——这只是给了我 var/log/ 下的文件我的电脑不是namenode中的文件。
总之,我想通过java访问hdfs-audit.log文件,和访问hdfs中的hdfs数据库和表等文件一样。有没有办法做到这一点。
【问题讨论】: