hadoop修改文件副本数

hadoop修改文件副本数

Hadoop上默认一个人间的副本数是3,这个也是可以再配置文件中<dfs.replication>参数修改的。

这里我们说一下,上传一个文件的时候更改文件的副本数。让他不用默认的副本数。

上传文件

命令上传文件,副本数为1

1
hadoop dfs -D dfs.replication=1 -put 123.lzo /temp/123.lzo

查看文件的副本数

查看整的dfs上的文件副本数

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
$ hadoop fsck -locations
....Status: HEALTHY
Total size: 86463643890 B (Total open files size: 415 B)
Total dirs: 93533
Total files: 200704
Total symlinks: 0 (Files currently being written: 6)
Total blocks (validated): 199798 (avg. block size 432755 B) (Total open file blocks (not validated): 5)
Minimally replicated blocks: 199798 (100.0 %)
Over-replicated blocks: 0 (0.0 %)
Under-replicated blocks: 2512 (1.2572699 %)
Mis-replicated blocks: 0 (0.0 %)
Default replication factor: 3
Average block replication: 2.9998398
Corrupt blocks: 0
Missing replicas: 17584 (2.8501685 %)
Number of data-nodes: 3
Number of racks: 1
FSCK ended at Thu Mar 28 10:27:24 CST 2019 in 6372 milliseconds

检查单个文件

1
2
3
4
5
$  hadoop fsck -locations  /temp/123.lzo
.......
Default replication factor: 3
Average block replication: 1.0
......

修改已经存在的文件副本数

  • 修改已保存文件的副本数量,为2副本
1
hadoop dfs -setrep 2 /shining/test.txt
  • 对文件夹中的所有文件都修改副本
1
hadoop dfs -setrep 2 -R /shining/
  • 选项是-w,表示等待副本操作结束才退出命令
1
hadoop dfs -setrep -R -w 1 /shining
感谢您的支持!