大数据之hdfs详解之五:垃圾回收站剖析

首先需要明白一点,现在linux系统好像没有回收站的说法了,所以在删除别人的文件或文件夹之前一定要慎重,毕竟rm命令是高危命令,删除了就没有了,所以对于高危命令,我们要保持敬畏之心.

hdfs在部署的时候默认垃圾回收站是禁用的,因此hdfs是可以开启垃圾回收站的。

先看看官网对回收站的解释:
第一个参数:fs.trash.interval=0 表示禁用

Number of minutes after which the checkpoint gets deleted. If zero,the trash feature is disabled. This option may be configured both on the server and the client. If trash is disabled server side then the client side configuration is checked. If trash is enabled on the server side then the value configured on the server is used and the client configuration value is ignored.

也就是说将fs.trash.interval的值表示检查点被删除之前的分钟数。 如果为零,则禁用垃圾箱功能。 可以在服务器和客户端上配置此选项。 如果在服务器端禁用垃圾,则检查客户端配置。 如果在服务器端启用了垃圾箱,则使用服务器上配置的值,并忽略客户端配置值。
那么可以按照生产上的需求设置回收站的保存时间,这个时间以分钟为单位,例如1440=24h=1天。

第二个参数:fs.trash.checkpoint.interval:0

Number of minutes between trash checkpoints. Should be smaller or equal to fs.trash.interval. If zero, the value is set to the value of fs.trash.interval. Every time the checkpointer runs it creates a new checkpoint out of current and removes checkpoints created more than fs.trash.interval minutes ago.

也就是说fs.trash.checkpoint.interval的值表示垃圾检查点之间的分钟数。 应该小于或等于fs.trash.interval。 如果为零,则将该值设置为fs.trash.interval的值。 每次检查点运行时,它都会创建一个新的检查点,并删除超过fs.trash.interval分钟前创建的检查点。

也就是默认为0。

那么我们需要在core-site.xml文件配置回收站
[hadoop@hadoop001 hadoop]$ vi core-site.xml
添加一下内容:
< property>
< name>fs.trash.interval< /name>
< value>1440< /value>
< /property>
< property>
< name>fs.trash.checkpoint.interval< /name>
< value>0< /value>
< /property>
在这里插入图片描述
然后重启(要先关闭)!!!

接着试着删除一些文件

[hadoop@hadoop001 hadoop-2.6.0-cdh5.7.0]$ hdfs dfs -rm /hahadata/NOTICE.txt
18/10/13 13:32:45 WARN util.NativeCodeLoader: Unable to load native-hadoop library for your platform… using builtin-java classes where applicable
18/10/13 13:33:08 INFO fs.TrashPolicyDefault: Moved: ‘hdfs://hadoop001:9000/hahadata/NOTICE.txt’ to trash at: hdfs://hadoop001:9000/user/hadoop/.Trash/Current/hahadata/NOTICE.txt

在这里插入图片描述
说明被清除掉的文件被移到了垃圾回收站里面了
可以在这个hdfs://hadoop001:9000/user/hadoop/.Trash/Current/hahadata/NOTICE.txt路径去恢复被删除的文件
存放在垃圾回收站的文件一旦超过了设置的时间,就是自动清空!!!

文件内容开了垃圾回收站是不会丢的,生产上必须要开启垃圾回收站,一般是7天或是14天或者更长

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章