设置上传副本数
1.在src/main/resources文件夹下创建 hdfs-site.xml 文件
1 <?xml version="1.0" encoding="UTF-8"?> 2 <!-- <!DOCTYPE xml> --> 3 <?xml-stylesheet type="text/xsl" href="configuration.xsl"?> 4 <configuration> 5 <property> 6 <name>dfs.replication</name> 7 <!-- 设置副本数为1 --> 8 <value>1</value> 9 </property> 10 </configuration>
2.文件上传
1 //文件上传 2 @Test 3 public void testCopyFromLocalFeil() throws IOException, InterruptedException, URISyntaxException { 4 5 //获取对象 6 Configuration conf = new Configuration(); 7 FileSystem fs = FileSystem.get(new URI("hdfs://192.168.12.161:9000"), conf, "hadoop"); 8 9 //执行上传API 10 fs.copyFromLocalFile(new Path("d:/Hadoop/HDFS/zxc.txt"), new Path("/qiuyun.txt")); 11 12 //关闭资源 13 fs.close(); 14 15 }
3.结果
4.优先级
在代码里的优先级最高
1 conf.set("dfs.replication", "2");
在资源目录下的hdfs-site.xml里的优先级第二,再其次是Hadoop集群上的hdfs-site.xml,最末尾的是defult的默认的。