Hadoop框架之——HDFS 2.x新特性

Hadoop2.x新特性

1 ,集群间数据拷贝

1)scp实现两个远程主机之间的文件复制

//推 push
scp -r hello.txt root@hadoop103:/user/root/hello.txt

//拉 pull
scp -r root@hadoop103:/user/root/hello.txt  hello.txt

//是通过本地主机中转实现两个远程主机的文件复制;如果在两个远程主机之间ssh没有配置的情况下可以使用该方式。
scp -r root@hadoop103:/user/root/hello.txt root@hadoop104:/user/root

2)采用distcp命令实现两个Hadoop集群之间的递归数据复制

[root@hadoop102 hadoop-3.1.3]$  bin/hadoop distcp hdfs://hadoop102:9000/user/root/hello.txt hdfs://hadoop105:9000/user/root/hello.txt

2, 小文件存档

在这里插入图片描述
1)案例实操

(1)需要启动YARN进程

[root@hadoop102 hadoop-2.7.2]$ start-yarn.sh

(2)归档文件
新建三个文件给它们放到/huan/input里面

[root@hadoop102 etc]# vim huanhuan.txt
[root@hadoop102 etc]# vim haoge.txt
[root@hadoop102 etc]# vim huanhao.txt
[root@hadoop102 etc]# hadoop fs -put huanhuan.txt /huan/input
[root@hadoop102 etc]# hadoop fs -put huanhao.txt /huan/input
[root@hadoop102 etc]# hadoop fs -put haoge.txt /huan/input

把/huan/input目录里面的所有文件归档成一个叫input.har的归档文件,并把归档后文件存储到/huan/output路径下。

[root@hadoop102 hadoop-2.7.2]$ hadoop archive -archiveName input.har -p  /huan/input  /huan/output

(3)查看归档

[root@hadoop102 hadoop-2.7.2]$ hadoop fs -ls /huan/output/input.har
[root@hadoop102 hadoop-2.7.2]$ hadoop fs -ls har:///huan/output/input.har
-rw-r--r--   3 root supergroup         17 2020-08-03 01:12 har:///huan/output/input.har/haoge.txt
-rw-r--r--   3 root supergroup         32 2020-08-03 01:12 har:///huan/output/input.har/huanhao.txt
-rw-r--r--   3 root supergroup         13 2020-08-03 01:12 har:///huan/output/input.har/huanhuan.txt

(4)解归档文件

[root@hadoop102 hadoop-2.7.2]$ hadoop fs -cp har:/// huan/output/input.har/*    /huan

3 回收站

开启回收站功能,可以将删除的文件在不超时的情况下,恢复原数据,起到防止误删除、备份等作用。

1.回收站参数设置及工作机制

在这里插入图片描述2.启用回收站
修改core-site.xml,配置垃圾回收时间为1分钟。


<property>
   <name>fs.trash.interval</name>
   <value>1</value>
</property>

3.查看回收站
回收站在集群中的路径:/user/root/.Trash/….

4.修改访问垃圾回收站用户名称
进入垃圾回收站用户名称,默认是dr.who,修改为root用户
[core-site.xml]

<property>
  <name>hadoop.http.staticuser.user</name>
  <value>root</value>
</property>

5. 通过程序删除的文件不会经过回收站,需要调用moveToTrash()才进入回收站

[root@hadoop102 hadoop-2.7.2]$ hadoop fs -rm /huan/haoge.txt

Trash trash = New Trash(conf);
trash.moveToTrash(path);

6.恢复回收站数据

[root@hadoop102 hadoop-2.7.2]$ hadoop fs -mv
/user/root/.Trash/Current/user/root/input    /user/atguigu/input

7.清空回收站

[root@hadoop102 hadoop-2.7.2]$ hadoop fs -expunge

4 快照管理

快照相当于对目录做一个备份。并不会立即复制所有文件,而是记录文件变化。

(1) hdfs dfsadmin -allowSnapshot路径(功能描述: 开启指定目录的快照功能)

(2) hdfs dfsadmin -di sallowSnapsh ot路径(功能描述: 禁用指定目录的快照功能,默认是禁用)

(3) h df’s dfs -createSnapshot路径 (功能描述:对目录创建快照)

(4) hdfs dfs -createSnap shot路径 名称(功能描述: 指定名称创建快照)

(5) hdfs dfs -ren ameSnapshot路径 旧名称新名称(功能描述:重命名快照)

(6) hdfs lsSnapshottableDir (功能描述: 列出当前用户所有可快照目录)

(7) hdfs snapshotDiff 路径1 路径2 (功能描述:比较两个快照目录的不同之处)

(8) hdfs dfs -del eteSnapsh ot (功能描述: 删除快照)

案例实操
(1)开启/禁用指定目录的快照功能

[root@hadoop102 hadoop-2.7.2]$ hdfs dfsadmin -allowSnapshot /user/huan/input

[root@hadoop102 hadoop-2.7.2]$ hdfs dfsadmin -disallowSnapshot /user/huan/input

(2)对目录创建快照

[root@hadoop102 hadoop-2.7.2]$ hdfs dfs -createSnapshot /user/huan/input

通过web访问hdfs://hadoop102:50070/user/atguigu/input/.snapshot/s……// 快照和源文件使用相同数据

[root@hadoop102 hadoop-2.7.2]$ hdfs dfs -lsr /user/huan/input/.snapshot/

(3) 指定名称创建快照

[root@hadoop102 hadoop-2.7.2]$ hdfs dfs -createSnapshot /user/huan/input  miao170508

(4)重命名快照

[root@hadoop102 hadoop-2.7.2]$ hdfs dfs -renameSnapshot /user/huan/input/  miao170508 huan170508

(5)列出当前用户所有可快照目录

[root@hadoop102 hadoop-2.7.2]$ hdfs lsSnapshottableDir

(6)比较两个快照目录的不同之处

[root@hadoop102 hadoop-2.7.2]$ hdfs snapshotDiff
 /user/huan/input/  .  .snapshot/huan170508	

(7)恢复快照

[root@hadoop102 hadoop-2.7.2]$ hdfs dfs -cp
/user/huan/input/.snapshot/s20170708-134303.027 /user
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值