ITPub博客

首页 > 数字化转型 > ERP > HDFS:利用archive管理大量小文件

HDFS:利用archive管理大量小文件

原创 ERP 作者:lihm01 时间:2013-06-13 14:38:58 0 删除 编辑

HDFS:利用archive管理大量小文件

1、查看原目录

[hadoop@hadoop1 ~]$ hadoop fs -lsr /tmp/hartest

-rw-r--r-- 2 hadoop supergroup 43 2013-06-13 13:56 /tmp/hartest/a.txt

-rw-r--r-- 2 hadoop supergroup 43 2013-06-13 13:56 /tmp/hartest/b.txt

-rw-r--r-- 2 hadoop supergroup 43 2013-06-13 13:56 /tmp/hartest/c.txt

2、创建归档

[hadoop@hadoop1 ~]$ hadoop archive -archiveName hartest.har -p /tmp/hartest /tmp/

13/06/13 14:09:38 INFO mapred.JobClient: Running job: job_201305151449_0067

13/06/13 14:09:39 INFO mapred.JobClient: map 0% reduce 0%

13/06/13 14:09:56 INFO mapred.JobClient: map 100% reduce 0%

13/06/13 14:10:05 INFO mapred.JobClient: map 100% reduce 33%

13/06/13 14:10:11 INFO mapred.JobClient: map 100% reduce 100%

13/06/13 14:10:16 INFO mapred.JobClient: Job complete: job_201305151449_0067

3、查看归档文件

[hadoop@hadoop1 ~]$ hadoop fs -lsr /tmp/hartest.har

-rw-r--r-- 2 hadoop supergroup 0 2013-06-13 14:10 /tmp/hartest.har/_SUCCESS

-rw-r--r-- 5 hadoop supergroup 258 2013-06-13 14:10 /tmp/hartest.har/_index

-rw-r--r-- 5 hadoop supergroup 23 2013-06-13 14:10 /tmp/hartest.har/_masterindex

-rw-r--r-- 2 hadoop supergroup 129 2013-06-13 14:09 /tmp/hartest.har/part-0

[hadoop@hadoop1 ~]$ hadoop fs -lsr har:///tmp/hartest.har

-rw-r--r-- 2 hadoop supergroup 43 2013-06-13 13:56 /tmp/hartest.har/c.txt

-rw-r--r-- 2 hadoop supergroup 43 2013-06-13 13:56 /tmp/hartest.har/a.txt

-rw-r--r-- 2 hadoop supergroup 43 2013-06-13 13:56 /tmp/hartest.har/b.txt

4、查看文件内容

[hadoop@hadoop1 ~]$ hadoop fs -cat

har:///tmp/hartest.har/c.txt

2013年 06月 13日 星期四 13:55:49 CST

[hadoop@hadoop1 ~]$ hadoop fs -cat har://hdfs-hadoop1:9000/tmp/hartest.har/c.txt

2013年 06月 13日 星期四 13:55:49 CST

5、如果使用API来访问HAR文件系统的文件,如下:

String uri = "har://hdfs-hadoop1:9000/tmp/hartest.har/c.txt";

Configuration conf = new Configuration();

FileSystem fs = FileSystem.get(URI.create(uri),conf);

FSDataInputStream in = null;

in = fs.open(new Path(uri));

IOUtils.copyBytes(in, System.out, 4096,false);

IOUtils.closeStream(in);

co� '#0�z� ��� font-kerning:0pt'>out, 4096,false);

IOUtils.closeStream(in);

[@more@]

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/23721637/viewspace-1060594/ ,如需转载,请注明出处,否则将追究法律责任。

下一篇: 没有了~
请登录后发表评论 登录
全部评论

注册时间:2010-04-14

  • 博文量
    36
  • 访问量
    124745