原本报错如下:
File /xiaoaa/hello2.txt could only be replicated to 0 nodes instead of minReplication (=1). There are 3 datanode(s) running and 3 node(s) are excluded in this operation.
说明一下,集群没问题,但就是出现了这个错误,导致数据远程无法写入,下面是代码
// 创建配置对象
Configuration conf = new Configuration();
conf.set("dfs.client.use.datanode.hostname", "true");
conf.set("dfs.replication","2");
// 定义统一资源标识符(uri: uniform resource identifier)
String uri = "hdfs://hadoop02:9000";
// 创建文件系统对象(基于HDFS的文件系统)
FileSystem fs = FileSystem.get(new URI(uri), conf,"hadoop");
// 创建路径对象(指向文件)
Path path = new Path(uri + "/xiaoaa/hello2.txt");
// 创建文件系统数据字节输出流(出水管:数据从程序到文件)
FSDataOutputStream out = fs.create(path);
// 通过字节输出流向文件写数据
out.write("Hello Hadoop World".getBytes());
// 关闭文件系统数据字节输出流
out.close();
// 关闭文件系统对象
fs.close();
// 提示用户写文件成功
System.out.println("文件[" + path + "]写入成功!");
我的这里设置的hadoop02需要在win10 hosts文件里面添加下,ip 名称。有几个添加几个。
错误显示存活的3个datanode都被排除了。为什么这样。
解决:
回忆一下hdfs写入流程,
1 和namenode进行通信,namenode会进行地址校验,权限校验,路径校验。9000端口开放了,这里没问题。
3 和datanode进行数据传输。这里需要建立连接。端口默认是50010。
叫运维开方端口50010,问题解决
在进行网络查询时,发现csdn部分要收费,我吐了。在外网找的。垃圾