情景描述:
在测试向HDFS从上传文件时,报java.io.IOException异常.
上传代码片段
private static void copyLocalFileToHDFS() {
InputStream in = null;
OutputStream out = null;
try {
in = new BufferedInputStream(new FileInputStream("pom.xml"));
Configuration configuration = new Configuration();
FileSystem fileSystem = FileSystem.get(new URI(saveUrl), configuration, "root");
out = fileSystem.create(new Path(saveUrl), new Progressable() {
@Override
public void progress() {
System.out.println(".");
}
});
IOUtils.copyBytes(in, out, 4096, true);
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (URISyntaxException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
} finally {
IOUtils.closeStream(in);
IOUtils.closeStream(out);
}
}
异常信息:
INFO hdfs.DFSClient: Exception in createBlockOutputStream
java.io.IOException: Bad connect ack with firstBadLink as 192.168.226.136:50010
at org.apache.hadoop.hdfs.DFSOutputStream$DataStreamer.createBlockOutputStream(DFSOutputStream.java:1116)
at org.apache.hadoop.hdfs.DFSOutputStream$DataStreamer.nextBlockOutputStream(DFSOutputStream.java:1039)
解决方式:
关闭data nodes 的防火墙
service iptables save
service iptables stop
chkconfig iptables off