问题描述
使用 HDFS 的Java API 上传文件时,报错:
File /dawang/3.txt could only be written to 0 of the 1 minReplication nodes. There are 1 datanode(s) running and 1 node(s) are excluded in this operation.
原因分析:
无法与 DataNode服务 通信,导致写流程报错
解决方案:
1. 开放 9866 端口
#开放 9866 端口
firewall-cmd --permanent --add-port=9866/tcp
#重启防火墙
systemctl restart firewalld.service
2. 在 IDEA 项目的resources目录下添加 hdfs-site.xml
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
<configuration>
<!-- 客户端连接datanode时是否使用datanode主机名(默认值:false)-->
<property>
<name>dfs.client.use.datanode.hostname</name>
<value>true</value>
</property>
</configuration>