大數據之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天或者更長

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