我正在研究hdfs,并将hfs-site.xml中的复制因子设置为1,如下所示:
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
<configuration>
<property>
<name>dfs.replication</name>
<value>1</value>
</property>
<property>
<name>dfs.namenode.name.dir</name>
<value>/Users/***/Documnent/hDir/hdfs/namenode</value>
</property>
<property>
<name>dfs.datanode.data.dir</name>
<value>/Users/***/Documnent/hDir/hdfs/datanode</value >
</property>
<property>
<name>dfs.permissions</name>
<value>false</value>
</property>
</configuration>
但当我尝试将一个文件从本地系统复制到hdfs文件系统时,我发现该文件的复制因子是3。下面是在hdfs上复制文件的代码:
public class FileCopyWithWrite {
public static void main(String[] args) {
// TODO Auto-generated method stub
String localSrc = "/Users/***/Documents/hContent/input/docs/1400-8.txt";
String dst = "hdfs://localhost/books/1400-8.txt";
try{
InputStream in = new BufferedInputStream(new FileInputStream(localSrc));
Configuration conf = new Configuration();;
FileSystem fs = FileSystem.get(URI.create(dst), conf);
OutputStream out = fs.create(new Path(dst), new Progressable() {
public void progress() {
// TODO Auto-generated method stub
System.out.println(".");
}
});
IOUtils.copyBytes(in, out, 4092, true);
}catch(Exception e){
e.printStackTrace();
}
}
}
请找到显示复制因子为3的屏幕截图:
注意,我是从伪分布式模式开始的,并且根据hadoop的文档更新了hdfs-site.xml。有什么关于为什么会这样的建议吗?
2条答案
按热度按时间nx7onnlm1#
如果在运行状态期间更改了上述属性,则需要重新启动集群,因为更改的属性只有在重新加载之后才会反映出来,这相当于重新启动集群。
qltillow2#
删除namenode目录和datanode目录为我解决了这个问题。所以我遵循以下程序:
停止服务,即dfs,yarn和mr。
删除hfs-site.xml文件中指定的namenode和datanote目录。
重新创建namenode和datanode目录。
重新启动服务,即dfs、yarn和mr。