在 CentOS 上调整 HDFS 副本数(replication),一般分为 全局默认副本数 和 指定文件/目录副本数 两种情况。
hdfs-site.xml编辑 HDFS 配置文件(路径视安装方式而定,常见如下):
vi $HADOOP_HOME/etc/hadoop/hdfs-site.xml
或(CDH/HDP 常见):
vi /etc/hadoop/conf/hdfs-site.xml
添加或修改:
<property>
<name>dfs.replication</name>
<value>2</value> <!-- 修改为想要的副本数 -->
</property>
副本数不能超过 DataNode 数量
stop-dfs.sh
start-dfs.sh
或(系统服务方式):
systemctl restart hadoop-hdfs-namenode
systemctl restart hadoop-hdfs-datanode
hdfs dfs -setrep 2 /user/hadoop/test.txt
hdfs dfs -setrep -R 2 /user/hadoop/
-R 表示递归(包括子目录)
hdfs dfs -stat %r /user/hadoop/test.txt
hdfs dfs -du -h /user/hadoop/
hdfs dfs -D dfs.replication=1 -put file.txt /tmp/
只对本次操作生效。
如果你能告诉我:
我可以给你更精确的操作命令。