HDFS高可恢复行,高抗灾行,很重要一点就是通过存放多个副本来保证的,但是根据集群的规模不同,可能要设置不同的复制数,可通过配置文件和程序来实现。
方法一:通过配置文件实现
在hdfs-site.xml中有个属性在hdfs-site.xml中有个属性
dfs.replication
3
Default block replication.
The actual number of replications can be specified when the file is created.
The default is used if replication is not specified in create time.
value默认为3,这个可以根据自己的情况设置。
方法二:在程序中设置
Configuration conf = new Configuration();
FileSystem fs = FileSystem.get(URI.create(hadoop_path), conf);
Path path = new Path(hadoop_path);
FSDataOutputStream out = fs.create(path);
// 控制复本数量-wt
fs.setReplication(path, (short) 1);
这里把复制数设为了1,在hdfs中只保存一个副本,通过管理webUI查看