2
원격 HDFS 시스템에서 파일을 읽고 내 로컬 컴퓨터의 콘솔에 표시하려고합니다. 로컬 컴퓨터는 .pem 파일 형식의 SSH 키로 만 HDFS 노드에 연결할 수 있습니다. 원격 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();
}
좋은 값. 그런 문제를 디버깅하기 위해 Hadoop Admin 명령어를 사용해야한다고 생각합니다. – Azim
Nirmal Ram에 감사드립니다. 하지만 파일의 상태가 HEALTH 인 것만 확인했습니다. – Janaarthan