HDFS 复制 属性 未反映 hfs-site.xml 中的定义

HDFS replication property not reflecting as defined in hfs-site.xml

我在 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。关于为什么会发生这种情况有什么建议吗?

删除namenode目录和datanode目录解决了我的问题。 所以我遵循了以下程序:

  1. 停止服务,即 dfs、yarn 和 mr.

  2. 删除hfs-site.xml文件中指定的namenode和datanote目录。

  3. 重新创建namenode和datanode目录。

  4. 重新启动服务,即 dfs、yarn 和 mr.

如果在 运行 状态期间更改了上述 属性,则需要集群 重新启动 以反映更改的 属性只有在重新加载它们之后,这相当于重新启动集群。