`

hdfs文件归档 Hadoop Archives

阅读更多

 

 

 

应用场景

hdfs中可能保存大量小文件(当然不产生小文件是最佳实践),这样会把namenode的namespace搞的很大。namespace保存着hdfs文件的inode信息,文件越多需要的namenode内存越大,但内存毕竟是有限的(这个是目前hadoop的硬伤)。

下面图片展示了,har文档的结构。har文件是通过mapreduce生成的,job结束后源文件不会删除。

 hdfs并不擅长存储小文件,因为每个文件最少占用一个block,每个block的元数据都会在namenode节点占用内存,如果存在这样大量的小文件,它们会吃掉namenode节点的大量内存。

hadoop Archives可以有效的处理以上问题,他可以把多个文件归档成为一个文件,归档成一个文件后还可以透明的访问每一个文件,并且可以做为mapreduce任务的输入。

3)、优缺点分析

Hadoop archive 唯一的优势可能就是将众多的小文件打包成一个har 文件了,那这个文件就会按照dfs.block.size 的大小进行分块,因为hdfs为每个块的元数据大小大约为150个字节,如果众多小文件的存在(什么是小文件内,就是小于dfs.block.size 大小的文件,这样每个文件就是一个block)占用大量的namenode 堆内存空间,打成har 文件可以大大降低namenode 守护节点的内存压力。但对于MapReduce 来说起不到任何作用,因为har文件就相当一个目录,仍然不能讲小文件合并到一个split中去,一个小文件一个split ,任然是低效的,这里要说一点<<hadoop 权威指南 中文版>>对这个翻译有问题,上面说可以分配到一个split中去,但是低效的。

删除与恢复:

hdfs文件被归档后,系统不会自动删除源文件,需要手动删除。

hadoop fs -rmr /user/hadoop/xxx/201310/*.*.*     正则表达式来删除的,大家根据自己的需求删除原始文件

有人说了,我删了,归档文件存在,源文件不在了,如果要恢复怎么办,其实这也很简单,直接从har 文件中 cp出来就可以了。

hadoop fs -cp /user/xxx/201310/201310.har/*  /user/hadoop/xxx/201310/

 

说明:

 

hadoop archive -archiveName test_save_foo.har -p  /foo/bar      a/b/c e/f/g  /user/outputdir/

以上是将/foo/bar文件夹下面的a/b/c和e/f/g两个目录的内容压缩归档到/user/outputdir/文件夹下,并且源文件不会被更改或者删除。注意,路径a/b/c 和e/f/g都是/foo/bar 的子文件夹

以下写法是错误的。

hadoop archive -archiveName test_save_foo.har -p  /foo/bar/a/b/c /foo/bar/e/f/g  /user/outputdir/  

报错如下:

source path /foo/bar/a/b/c is not relative  to /foo/bar/e/f/g

 

 

 

命令说明:

 

1)、单个src文件夹

hadoop archive -archiveName test_save_foo.har -p  /foo/bar/ 419 /user/outputdir/  

2)、多个src文件夹

hadoop archive -archiveName test_save_foo.har -p  /foo/bar/ 419  510 /user/outputdir/  

3)、不指定src path,直接归档parent path(本例为“ /foo/bar/20120116/ ”, “ /user/outputdir ”仍然为输出path),这招是从源码里翻出来的。

hadoop archive -archiveName test_save_foo.har -p  /foo/bar/  /user/outputdir/  
4)、 使用模式匹配的src path,下面的示例归档10、11、12月文件夹的数据。这招也是从源码发出来的。
hadoop archive -archiveName combine.har -p  /foo/bar/2011 1[0-2]  /user/outputdir/  

 

 

案例:

1)、将要归档的的hdfs存储目录:
[yz@hai-hadoop06-prd-yz new]$ hadoop dfs -ls  /hai_yz/hive/class_room/pomelo_chat_mes/
DEPRECATED:
Useof this script toexecute hdfs command is deprecated.
Instead
use the hdfs command for it.
Found2 items
drwxr-xr-x   - simth_yz supergroup         
02017-11-2716:45 /hai_yz/hive/class_room/pomelo_chat_mes/2017-11-26
drwxr-xr-x   - simth_yz supergroup         
02017-11-2811:46 /hai_yz/hive/class_room/pomelo_chat_mes/2017-11-27
[yz@hai-hadoop06-prd-yz
new]$ hadoop dfs -ls  /hai_yz/hive/class_room/frontend_dot
DEPRECATED:
Useof this script toexecute hdfs command is deprecated.
Instead
use the hdfs command for it.
Found1 items
drwxr-xr-x   -
work supergroup          02018-01-1118:52 /hai_yz/hive/class_room/frontend_dot/2018-01-10
[yaoyingzhe@haibian-hadoop06-prd-yz weike_chat_new]$

2)、进行归档压缩命令:
[yz@hai-hadoop06-prd-yz
new]$ hadoop archive -archiveName test.har -p /hai_yz/hive/class_room/  frontend_dot  pomelo_chat_mes /haibi/yz/test

3)、查看压缩文件的组成结构:
[yaoyingzhe@haibian-hadoop06-prd-yz weike_chat_new]$ hadoop dfs -ls /haibi/yz/
test/test.har
DEPRECATED:
Useof this script toexecute hdfs command is deprecated.
Instead
use the hdfs command for it.
Found4 items
-rw-r
--r--   3 simth_yz supergroup          0 2018-01-25 11:13 /haibi/yz/test/test.har/_SUCCESS
-rw-r
--r--   5 simth_yz supergroup       3105 2018-01-25 11:13 /haibi/yz/test/test.har/_index
-rw-r
--r--   5 simth_yz supergroup         24 2018-01-25 11:13 /haibi/yz/test/test.har/_masterindex
-rw-r
--r--   3 simth_yz supergroup   18743845 2018-01-25 11:13 /haibi/yz/test/test.har/part-0
[yaoyingzhe@haibian-hadoop06-prd-yz weike_chat_new]$

4)、使用hdfs文件系统查看har文件目录内容
[yz@hai-hadoop06-prd-yz
new]$ hadoop dfs -ls  har:///haibi/yz/test/test.har/*
DEPRECATED: Use of this script to execute hdfs command is deprecated.
Instead use the hdfs command for it.
Found 1 items
drwxr-xr-x   - simth_yz supergroup          0 2018-01-11 18:52 har:///haibi/yz/test/test.har/frontend_dot/2018-01-10
Found 2 items
drwxr-xr-x   - simth_yz supergroup          0 2017-11-27 16:45 har:///haibi/yz/test/test.har/pomelo_chat_mes/2017-11-26
drwxr-xr-x   - simth_yz supergroup          0 2017-11-28 11:46 har:///haibi/yz/test/test.har/pomelo_chat_mes/2017-11-27

5)、使用hdfs文件系统查看har文件具体的内容
[yz@hai-hadoop06-prd-yz new]$ hadoop dfs -cat  har:///haibi/yz/test/test.har/*/
*/*

 

 

案例:

 

分享到:
评论

相关推荐

    apache hadoop 2.7.2.chm

    Hadoop Archives DistCp GridMix Rumen Scheduler Load Simulator Reference Release Notes API docs Common CHANGES.txt HDFS CHANGES.txt MapReduce CHANGES.txt YARN CHANGES.txt Metrics ...

    hadoop 权威指南(第三版)英文版

    Using Hadoop Archives Limitations 4. Hadoop I/O . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83 Data Integrity Data Integrity ...

    Hadoop Archives

    文章目录OverviewHow to Create an ArchiveHow to Look Up ...一个 Hadoop archive 对应一个文件系统目录。 Hadoop archive 的扩展名是 *.har。Hadoop archive 包含元数据(形式是 _index 和 _masterindx)和数据(p

    Hadoop官方中文帮助文档1.1.0

    本文档为Apache官方Hadoop 1.1.0中文文档 文档目录: 1.概述 2.快速入门 3.集群搭建 4.HDFS构架设计 5.HDFS使用指南 6.HDFS权限指南 ...14.Hadoop Archives 15.Hadoop On Demand 另附带 Hadoop API

    hadoop-2.2.0-x64.tar.gz part3

    [INFO] Apache Hadoop Archives ............................ SUCCESS [2.099s] [INFO] Apache Hadoop Rumen ............................... SUCCESS [6.924s] [INFO] Apache Hadoop Gridmix ......................

    hadoop-2.2.0-x64.tar.gz part2

    [INFO] Apache Hadoop Archives ............................ SUCCESS [2.099s] [INFO] Apache Hadoop Rumen ............................... SUCCESS [6.924s] [INFO] Apache Hadoop Gridmix ......................

    hadoop_the_definitive_guide_3nd_edition

    Using Hadoop Archives 79 Limitations 80 4. Hadoop I/O . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83 Data Integrity 83 Data ...

    hadoop-2.2.0-x64.tar.gz part1

    [INFO] Apache Hadoop Archives ............................ SUCCESS [2.099s] [INFO] Apache Hadoop Rumen ............................... SUCCESS [6.924s] [INFO] Apache Hadoop Gridmix ......................

    Hadoop分布式Cache

    DistributedCache 是一个提供给Map/Reduce框架的工具,用来缓存文件(text, archives, jars and so on)文件的默认访问协议为(hdfs://). ...文件在每个Job中只会被拷贝一次,缓存的归档文件会被在Slave节点中解压缩。

    muCommander 0.9.0

    Virtual filesystem with support for local volumes, FTP, SFTP, SMB, NFS, HTTP, Amazon S3, Hadoop HDFS and Bonjour Quickly copy, move, rename files, create directories, email files... Browse, create ...

Global site tag (gtag.js) - Google Analytics