zoukankan      html  css  js  c++  java
  • Hadoop基础(十四): HDFS 2.X新特性

    1 集群间数据拷贝

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

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

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

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

    //是通过本地主机中转实现两个远程主机的文件复制;如果在两个远程主机之间ssh没有配置的情况下可以使用该方式。

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

     

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

     

    2 小文件存档

    3.案例实操

    1需要启动YARN进程

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

    2归档文件

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

    [atguigu@hadoop102 hadoop-2.7.2]$ bin/hadoop archive -archiveName input.har –p  /user/atguigu/input   /user/atguigu/output

    3)查看归档

    [atguigu@hadoop102 hadoop-2.7.2]$ hadoop fs -lsr /user/atguigu/output/input.har
    [atguigu@hadoop102 hadoop-2.7.2]$ hadoop fs -lsr har:///user/atguigu/output/input.har

    4)解归档文件

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

    3 回收站

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

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

    2.启用回收站

    修改core-site.xml,配置垃圾回收时间1分钟。

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

    3.查看回收站

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

    4.修改访问垃圾回收站用户名称

    进入垃圾回收站用户名称,默认是dr.who,修改为atguigu用户

    [core-site.xml]

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

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

    Trash trash = New Trash(conf);

    trash.moveToTrash(path);

    6 恢复回收站数据

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

    7 清空回收站

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

    4 快照管理

    2案例实操

    1)开启/禁用指定目录的快照功能

    [atguigu@hadoop102 hadoop-2.7.2]$ hdfs dfsadmin -allowSnapshot /user/atguigu/input
    
    [atguigu@hadoop102 hadoop-2.7.2]$ hdfs dfsadmin -disallowSnapshot /user/atguigu/input

    2)对目录创建快照

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

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

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

    3)指定名称创建快照

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

    4)重命名快照

    [atguigu@hadoop102 hadoop-2.7.2]$ hdfs dfs -renameSnapshot /user/atguigu/input/  miao170508 atguigu170508

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

    [atguigu@hadoop102 hadoop-2.7.2]$ hdfs lsSnapshottableDir

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

    [atguigu@hadoop102 hadoop-2.7.2]$ hdfs snapshotDiff
     /user/atguigu/input/  .  .snapshot/atguigu170508    

    7)恢复快照

    [atguigu@hadoop102 hadoop-2.7.2]$ hdfs dfs -cp
    /user/atguigu/input/.snapshot/s20170708-134303.027 /user

     

     

  • 相关阅读:
    unalias---取消命令别名
    alias---设置别名
    type---显示指定命令的类型
    logout命令用于退出当前登录的Shell
    enable&&builtin---shell内部命令
    read---读取变量值
    readonly&&declare&&unset &&export&&env环境变量
    fc---输出历史命令列表
    command---调用指定的指令并执行
    terminfo 数据库?
  • 原文地址:https://www.cnblogs.com/qiu-hua/p/13326302.html
Copyright © 2011-2022 走看看