出现原因
21/11/16 15:13:17 WARN BlockReaderFactory: I/O error constructing remote block reader.
java.net.ConnectException: Connection timed out: no further information
...
...
Failed to connect to /192.168.0.53:9866 for block, add to deadNodes and continue. java.net.ConnectException: Connection timed out: no further information
通过日志可以看出,是本地中无法连接到192.168.0.53:9866,查看自己的网络可以发现192.168.0.53是内部网络,也就是namenode与DataNonde的通信是采用内网进行通信的,我们再本地调试的时候需要指定网络为外网网络
修改方式
方式一:
修改IDEA中的hdfs-site.xml文件,添加或者修改如下内容:
<property>
<name>dfs.client.use.datanode.hostname</name>
<value>true</value>
</property>
此时再运行程序的时候就可以直接通过了
方式二:
再代码中指定NM和DN之间的通信为外网,此方式仅适用于api操作HDFS
Configuration conf = new Configuration(); //设置通过域名访问datanode
conf.set("dfs.client.use.datanode.hostname", "true");
通过两种方式,建议使用第一种