12)HDFS 2.x 新特性

2018-11-19  本文已影响0人  bullion

集群间数据拷贝

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

# 推 push

$ scp -r hello.txt root@hadoop103:/user/atguigu/hello.txt

# 拉 pull

$ scp -r root@hadoop103:/user/atguigu/hello.txt hello.txt

# 是通过本

$ scp -r root@hadoop103:/user/atguigu/hello.txt root@hadoop104:/user/atguigu

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

$ bin/hadoop distcp hdfs://hadoop102:9000/user/atguigu/hello.text hdfs://hadoop103:9000/user/atguigu/hello.text

小文件存档案例

1)需要启动YARN进程

$ start-yarn.sh

2)归档文件

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

$ bin/hadoop archive -archiveName input.har -p /user/atguigu/input /user/atguigu/output

3)查看归档

$ hadoop fs  -lsr /user/atguigu/output/input.har

$ hadoop fs  -lsr har:///user/atguigu/output/input.har

回收站

开启回收站功能,可以将删除的文件在不超时的情况下,恢复原数据,防止误删除

回收站参数

1)默认值 fs.trash.interval = 0, 0表示禁用回收站;其他值表示设置文件的存活时间

2)默认值 fs.trash.checkpoint.interval = 0, 检查回收站的间隔时间。如果该值为0,则该值设置和 fs.trash.interval 的参数值相等

3)要求fs.trash.checkpoint.interval <= fs.trash.interval

启用回收站

core-site.xml

# 配置垃圾回收时间为1分钟

<property>

    <name>fs.trash.interval</name>

    <value>1</value>

</property>

修改访问回收站的用户名称

core-site.xml

<property>

    <name>hadoop.http.staticuser.user</name>

    <value>atguigu</value>

</property>

查看回收站

回收站在集群中的路径:/user/atguigu/.Trash/...

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

Trash trash = new Trash(conf);

trash.moveToTrash(path);

恢复回收站数据

$ hadoop fs -mv /user/atguigu/.Trash/Current/user/atguigu/input /user/atguigu/input

清空回收站

$ hadoop fs -expunge

快照

快照相当于对目录做一个备份(相当于备份namenode)。并不会立即复制所有文件,而是指向同一个文件。当写入发生时,才会产生新文件。

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

2)hdfs dfsadmin -disallowSnapshot 路径 (禁用指定目录的快照功能,默认是禁用,禁用之前要删除路径中的所有快照)

3)hdfs dfs -createSnapshot 路径 (对目录创建快照)

4)hdfs dfs -createSnapshot 路径 名称 (指定名称创建快照)

5)hdfs dfs -renameSnapshot 路径 旧名称 新名称 (重命名快照)

6)hdfs lsSnapshottableDir (列出当前用户所有可快照目录)

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

8)hdfs dfs -deleteSnapshot <path> <snapshotName> (删除快照)

上一篇 下一篇

猜你喜欢

热点阅读