HDFS 2.X新特性

1 集群间数据拷贝

1.scp实现两个远程主机之间的文件复制
scp -r hello.txt root@hadoop103:/user/ch/hello.txt		// 推 push
scp -r root@hadoop103:/user/ch/hello.txt  hello.txt		// 拉 pull
scp -r root@hadoop103:/user/ch/hello.txt root@hadoop104:/user/ch   //是通过本地主机中转实现两个远程主机的文件复制;如果在两个远程主机之间ssh没有配置的情况下可以使用该方式。
2.采用distcp命令实现两个Hadoop集群之间的递归数据复制

[ch@hadoop102 hadoop-2.7.2]$ bin/hadoop distcp
hdfs://haoop102:9000/user/ch/hello.txt hdfs://hadoop103:9000/user/ch/hello.txt

2 小文件存档

案例实操

(1)需要启动YARN进程
[ch@hadoop102 hadoop-2.7.2]$ start-yarn.sh
(2)归档文件
把/user/ch/input目录里面的所有文件归档成一个叫input.har的归档文件,并把归档后文件存储到/user/ch/output路径下。
[ch@hadoop102 hadoop-2.7.2]$ bin/hadoop archive -archiveName input.har –p /user/ch/input /user/ch/output
(3)查看归档
[ch@hadoop102 hadoop-2.7.2]$ hadoop fs -lsr /user/ch/output/input.har
[ch@hadoop102 hadoop-2.7.2]$ hadoop fs -lsr har:///user/ch/output/input.har
(4)解归档文件
[ch@hadoop102 hadoop-2.7.2]$ hadoop fs -cp har:/// user/ch/output/input.har/* /user/ch

3 回收站

开启回收站功能,可以将删除的文件在不超时的情况下,恢复原数据,起到防止误删除、备份等作用。
1.回收站参数设置及工作机制
图3-19 回收站
2.启用回收站

修改core-site.xml,配置垃圾回收时间为1分钟。
<property>
   <name>fs.trash.interval</name>
<value>1</value>
</property>

3.查看回收站
回收站在集群中的路径:/user/ch/.Trash/….
4.修改访问垃圾回收站用户名称
进入垃圾回收站用户名称,默认是dr.who,修改为ch用户

修改[core-site.xml]配置
<property>
  <name>hadoop.http.staticuser.user</name>
  <value>ch</value>
</property>

5.通过程序删除的文件不会经过回收站,需要调用moveToTrash()才进入回收站
Trash trash = New Trash(conf);
trash.moveToTrash(path);
6. 恢复回收站数据
[ch@hadoop102 hadoop-2.7.2]$ hadoop fs -mv /user/ch/.Trash/Current/user/ch/input /user/ch/input
7. 清空回收站
[ch@hadoop102 hadoop-2.7.2]$ hadoop fs -expunge

4 快照管理

案例实操

(1)开启/禁用指定目录的快照功能
[ch@hadoop102 hadoop-2.7.2]$ hdfs dfsadmin -allowSnapshot /user/ch/input
[ch@hadoop102 hadoop-2.7.2]$ hdfs dfsadmin -disallowSnapshot /user/ch/input
(2)对目录创建快照
[ch@hadoop102 hadoop-2.7.2]$ hdfs dfs -createSnapshot /user/ch/input
通过web访问hdfs://hadoop102:50070/user/ch/input/.snapshot/s……// 快照和源文件使用相同数据
[ch@hadoop102 hadoop-2.7.2]$ hdfs dfs -lsr /user/ch/input/.snapshot/
(3)指定名称创建快照
[ch@hadoop102 hadoop-2.7.2]$ hdfs dfs -createSnapshot /user/ch/input miao170508
(4)重命名快照
[ch@hadoop102 hadoop-2.7.2]$ hdfs dfs -renameSnapshot /user/ch/input/ miao170508 ch170508
(5)列出当前用户所有可快照目录
[ch@hadoop102 hadoop-2.7.2]$ hdfs lsSnapshottableDir
(6)比较两个快照目录的不同之处
[ch@hadoop102 hadoop-2.7.2]$ hdfs snapshotDiff
/user/ch/input/ . .snapshot/ch170508
(7)恢复快照
[ch@hadoop102 hadoop-2.7.2]$ hdfs dfs -cp
/user/ch/input/.snapshot/s20170708-134303.027 /user

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值