作业:当使用hadoop fs -put上传一个文件到hdfs时,
(1)如果目的地是一个已经存在的目录时,上传后的文件名是什么?
答:
----准备工作:清空hdfs
[cr12@chaoren1 ~]$ hadoop fs -rmr hdfs://chaoren1:9012/*
Deleted hdfs://chaoren1:9012/mnt
Deleted hdfs://chaoren1:9012/user
Deleted hdfs://chaoren1:9012/mnt
Deleted hdfs://chaoren1:9012/user
----创建目录test
[cr12@chaoren1 ~]$ hadoop fs -mkdir /test
[cr12@chaoren1 ~]$ hadoop fs -ls hdfs://chaoren1:9012/
Found 1 items
drwxr-xr-x - cr12 supergroup 0 2014-04-09 12:34 /test
[cr12@chaoren1 ~]$ hadoop fs -ls hdfs://chaoren1:9012/
Found 1 items
drwxr-xr-x - cr12 supergroup 0 2014-04-09 12:34 /test
----上传文件hello.txt到test目录下
[cr12@chaoren1 ~]$ hadoop fs -put hello.txt /test
[cr12@chaoren1 ~]$ hadoop fs -ls hdfs://chaoren1:9012/test
Found 1 items
-rw-r--r-- 3 cr12 supergroup 19 2014-04-09 12:36 /test/hello.txt
[cr12@chaoren1 ~]$ hadoop fs -ls hdfs://chaoren1:9012/test
Found 1 items
-rw-r--r-- 3 cr12 supergroup 19 2014-04-09 12:36 /test/hello.txt
结论:如果目的地是一个已经存在的目录时,上传后会在已存在的目录下生成和上传文件同名的文件,即/test/hello.txt
(2)如果目的地是一个不存在的路径时,上传后的文件名是什么?
答:
----上传hello.txt到不存在的路径/test2
[cr12@chaoren1 ~]$ hadoop fs -put hello.txt /test2
[cr12@chaoren1 ~]$ hadoop fs -ls hdfs://chaoren1:9012/test2/
Found 1 items
-rw-r--r-- 3 cr12 supergroup 19 2014-04-09 12:40 /test2
[cr12@chaoren1 ~]$ hadoop fs -text /test2
hello you
hello me
Found 1 items
-rw-r--r-- 3 cr12 supergroup 19 2014-04-09 12:40 /test2
[cr12@chaoren1 ~]$ hadoop fs -text /test2
hello you
hello me
结论:如果目的地是一个不存在的目录,上传后的文件名与该路径的文件名一致,并且该文件不是文件夹,内容和上传的文件内容一样
(3)如果目的地是一个已经存在的文件时,上传后的文件名是什么?
答:
[cr12@chaoren1 ~]$ mv hello.txt hello.new
[cr12@chaoren1 ~]$ ls
hello.new soft
[cr12@chaoren1 ~]$ ls
hello.new soft
[cr12@chaoren1 ~]$ hadoop fs -put hello.new /test/hello.txt
put: Target /test/hello.txt already exists
put: Target /test/hello.txt already exists
结论:执行不成功,会报该文件已存在错误
作业:修改自己集群的hdfs-site.xml中的dfs.name.dir的值,改为多个路径。观察内容变化,以及删除一个内容后的集群变化情况。
(注意:1.逗号分隔符是英文的,逗号前后无任何空格 2.目录必须是存在的)
答:
----在主目录下创建tmp文件夹
[cr12@chaoren1 ~]$ mkdir tmp
----修改dfs.name.dir的值,增加
/
mnt/home/cr12/tmp
<property>
<name>dfs.name.dir</name>
<value>${hadoop.tmp.dir}/dfs/name
,/
mnt/home/cr12/tmp
</value>
</property>
----查看tmp目录下的内容(需重启集群)
[cr12@chaoren1 ~]$ cd tmp
[cr12@chaoren1 tmp]$ ls
current image in_use.lock
[cr12@chaoren1 tmp]$ ls
current image in_use.lock
结论:dfs.name.dir的值每增加一个路径,hadoop会将namenode的临时文件信息在相应路径下拷贝多份
----删除新增的tmp目录下
[cr12@chaoren1 ~]$ cd tmp
[cr12@chaoren1 tmp]$ ls
current image in_use.lock
[cr12@chaoren1 tmp]$ cd current/
[cr12@chaoren1 current]$ ls
edits edits.new fsimage fstime VERSION
[cr12@chaoren1 current]$ rm edits
[cr12@chaoren1 current]$ ls
edits.new fsimage fstime VERSION
[cr12@chaoren1 tmp]$ ls
current image in_use.lock
[cr12@chaoren1 tmp]$ cd current/
[cr12@chaoren1 current]$ ls
edits edits.new fsimage fstime VERSION
[cr12@chaoren1 current]$ rm edits
[cr12@chaoren1 current]$ ls
edits.new fsimage fstime VERSION
----重启集群后查看
[cr12@chaoren1 current]$ ls
edits.new fsimage fstime VERSION
作业:当上传一个文件/mnt/software/hadoop-1.1.2.tar.gz 到hdfs后,查看DataNode中的数据块实际占用大小。
(结果包含有几个块,分别是多大)
[cr12@chaoren1 current]$ hadoop fs -put /mnt/software/hadoop-1.1.2.tar.gz /
[cr12@chaoren3 current]$ ls -lh
total 60M
-rw-rw-r-- 1 cr12 cr12 60M Apr 9 13:08 blk_7691844102163069985
-rw-rw-r-- 1 cr12 cr12 473K Apr 9 13:08 blk_7691844102163069985_1020.meta
-rw-rw-r-- 1 cr12 cr12 1.2K Apr 9 13:01 dncp_block_verification.log.curr
-rw-rw-r-- 1 cr12 cr12 157 Apr 9 13:01 VERSION
total 60M
-rw-rw-r-- 1 cr12 cr12 60M Apr 9 13:08 blk_7691844102163069985
-rw-rw-r-- 1 cr12 cr12 473K Apr 9 13:08 blk_7691844102163069985_1020.meta
-rw-rw-r-- 1 cr12 cr12 1.2K Apr 9 13:01 dncp_block_verification.log.curr
-rw-rw-r-- 1 cr12 cr12 157 Apr 9 13:01 VERSION
结论:在默认块大小是64M的情况下,60M的hadoop-1.1.2.tar.gz文件在DataNode中的数据块实际占用空间也为60M,占用一个块