HDFS集群中大数据运维常用的命令总结

            HDFS集群中大数据运维常用的命令概述

                                        作者:尹正杰

版权声明:原创作品,谢绝转载!否则将追究法律责任。

 

 

 

 

一.HDFS集群常用命令

1>.查看hdfs集群某路径下的文件或目录

[root@hadoop101.yinzhengjie.org.cn ~]# hdfs dfs -ls /
Found 4 items
drwxr-xr-x   - root supergroup          0 2020-03-12 19:20 /inputDir
drwxr-xr-x   - root supergroup          0 2020-03-12 19:20 /outputDir
drwxrwx---   - root supergroup          0 2020-03-12 19:20 /tmp
drwxrwx---   - root supergroup          0 2020-03-12 16:51 /yinzhengjie
[root@hadoop101.yinzhengjie.org.cn ~]# 
[root@hadoop101.yinzhengjie.org.cn ~]# hdfs dfs -ls /                    #仅查看HDFS的根路径下存在的文件或目录
[root@hadoop101.yinzhengjie.org.cn ~]# hdfs dfs -ls -R / 
drwxr-xr-x   - root supergroup          0 2020-03-12 19:20 /inputDir
-rw-r--r--   3 root supergroup         60 2020-03-12 19:20 /inputDir/wc.txt
drwxr-xr-x   - root supergroup          0 2020-03-12 19:20 /outputDir
-rw-r--r--   3 root supergroup          0 2020-03-12 19:20 /outputDir/_SUCCESS
-rw-r--r--   3 root supergroup         54 2020-03-12 19:20 /outputDir/part-r-00000
drwxrwx---   - root supergroup          0 2020-03-12 19:20 /tmp
drwxrwx---   - root supergroup          0 2020-03-12 15:40 /tmp/hadoop-yarn
drwxrwx---   - root supergroup          0 2020-03-12 16:22 /tmp/hadoop-yarn/staging
drwxrwx---   - root supergroup          0 2020-03-12 15:40 /tmp/hadoop-yarn/staging/history
drwxrwx---   - root supergroup          0 2020-03-12 16:23 /tmp/hadoop-yarn/staging/history/done
drwxrwx---   - root supergroup          0 2020-03-12 16:23 /tmp/hadoop-yarn/staging/history/done/2020
drwxrwx---   - root supergroup          0 2020-03-12 16:23 /tmp/hadoop-yarn/staging/history/done/2020/03
drwxrwx---   - root supergroup          0 2020-03-12 16:23 /tmp/hadoop-yarn/staging/history/done/2020/03/12
drwxrwx---   - root supergroup          0 2020-03-12 16:23 /tmp/hadoop-yarn/staging/history/done/2020/03/12/000000
-rwxrwx---   3 root supergroup      33748 2020-03-12 16:23 /tmp/hadoop-yarn/staging/history/done/2020/03/12/000000/job_1583999614207_0001-1584001369965-root-word+count-1584001390351-1-1-SUCCEEDED-default-1584001376310.jhist
-rwxrwx---   3 root supergroup     203051 2020-03-12 16:23 /tmp/hadoop-yarn/staging/history/done/2020/03/12/000000/job_1583999614207_0001_conf.xml
drwxrwxrwt   - root supergroup          0 2020-03-12 16:22 /tmp/hadoop-yarn/staging/history/done_intermediate
drwxrwx---   - root supergroup          0 2020-03-12 16:23 /tmp/hadoop-yarn/staging/history/done_intermediate/root
drwx------   - root supergroup          0 2020-03-12 16:22 /tmp/hadoop-yarn/staging/root
drwx------   - root supergroup          0 2020-03-12 19:20 /tmp/hadoop-yarn/staging/root/.staging
drwxrwxrwt   - root root                0 2020-03-12 19:20 /tmp/logs
drwxrwx---   - root root                0 2020-03-12 19:20 /tmp/logs/root
drwxrwx---   - root root                0 2020-03-12 19:20 /tmp/logs/root/logs
drwxrwx---   - root root                0 2020-03-12 19:21 /tmp/logs/root/logs/application_1584011863930_0001
-rw-r-----   3 root root            58844 2020-03-12 19:21 /tmp/logs/root/logs/application_1584011863930_0001/hadoop103.yinzhengjie.org.cn_25441
-rw-r-----   3 root root            53748 2020-03-12 19:21 /tmp/logs/root/logs/application_1584011863930_0001/hadoop104.yinzhengjie.org.cn_34288
drwxrwx---   - root supergroup          0 2020-03-12 16:51 /yinzhengjie
drwxrwx---   - root supergroup          0 2020-03-12 16:51 /yinzhengjie/jobhistory
drwxrwx---   - root supergroup          0 2020-03-12 16:54 /yinzhengjie/jobhistory/manager
drwxrwx---   - root supergroup          0 2020-03-12 16:54 /yinzhengjie/jobhistory/manager/2020
drwxrwx---   - root supergroup          0 2020-03-12 16:54 /yinzhengjie/jobhistory/manager/2020/03
drwxrwx---   - root supergroup          0 2020-03-12 16:54 /yinzhengjie/jobhistory/manager/2020/03/12
drwxrwx---   - root supergroup          0 2020-03-12 19:20 /yinzhengjie/jobhistory/manager/2020/03/12/000000
-rwxrwx---   3 root supergroup      33731 2020-03-12 16:54 /yinzhengjie/jobhistory/manager/2020/03/12/000000/job_1584002509171_0001-1584003247341-root-word+count-1584003263906-1-1-SUCCEEDED-default-1584003252477.jhist
-rwxrwx---   3 root supergroup     202992 2020-03-12 16:54 /yinzhengjie/jobhistory/manager/2020/03/12/000000/job_1584002509171_0001_conf.xml
-rwxrwx---   3 root supergroup      33735 2020-03-12 19:09 /yinzhengjie/jobhistory/manager/2020/03/12/000000/job_1584010951301_0001-1584011344282-root-word+count-1584011360241-1-1-SUCCEEDED-default-1584011349879.jhist
-rwxrwx---   3 root supergroup     202988 2020-03-12 19:09 /yinzhengjie/jobhistory/manager/2020/03/12/000000/job_1584010951301_0001_conf.xml
-rwxrwx---   3 root supergroup      33732 2020-03-12 19:20 /yinzhengjie/jobhistory/manager/2020/03/12/000000/job_1584011863930_0001-1584012039874-root-word+count-1584012056179-1-1-SUCCEEDED-default-1584012045689.jhist
-rwxrwx---   3 root supergroup     202988 2020-03-12 19:20 /yinzhengjie/jobhistory/manager/2020/03/12/000000/job_1584011863930_0001_conf.xml
drwxrwxrwt   - root supergroup          0 2020-03-12 16:54 /yinzhengjie/jobhistory/tmp
drwxrwx---   - root supergroup          0 2020-03-12 19:20 /yinzhengjie/jobhistory/tmp/root
[root@hadoop101.yinzhengjie.org.cn ~]# 
[root@hadoop101.yinzhengjie.org.cn ~]# 
[root@hadoop101.yinzhengjie.org.cn ~]# hdfs dfs -ls -R /                  #递归查看HDFS的根路径下存在的文件或目录

2>.查看某个目录的文件大小

[root@hadoop101.yinzhengjie.org.cn ~]# hdfs dfs -du  -x /
60      /inputDir
54      /outputDir
349391  /tmp
710166  /yinzhengjie
[root@hadoop101.yinzhengjie.org.cn ~]# 
[root@hadoop101.yinzhengjie.org.cn ~]# hdfs dfs -du -x /                   #查看根路径下各文件或目录的大小,默认以字节形式显示
[root@hadoop101.yinzhengjie.org.cn ~]# hdfs dfs -du /
60      /inputDir
54      /outputDir
349391  /tmp
710166  /yinzhengjie
[root@hadoop101.yinzhengjie.org.cn ~]# 
[root@hadoop101.yinzhengjie.org.cn ~]# 
[root@hadoop101.yinzhengjie.org.cn ~]# hdfs dfs -du /                     #输出结果同上,即默认就是"-x"选项
[root@hadoop101.yinzhengjie.org.cn ~]# hdfs dfs -du  -s /
1059671  /
[root@hadoop101.yinzhengjie.org.cn ~]# 
[root@hadoop101.yinzhengjie.org.cn ~]# hdfs dfs -du -s /                  #仅查看根目录的总大小,默认以字节形式显示
[root@hadoop101.yinzhengjie.org.cn ~]# hdfs dfs -du  -h /
60       /inputDir
54       /outputDir
341.2 K  /tmp
693.5 K  /yinzhengjie
[root@hadoop101.yinzhengjie.org.cn ~]# 
[root@hadoop101.yinzhengjie.org.cn ~]# hdfs dfs -du -h /                  #查看根路径下各文件或目录的大小,以人性化的方式显示文件大小

3>.查看文件系统的使用情况

[root@hadoop101.yinzhengjie.org.cn ~]# hdfs dfs -df
Filesystem                                         Size     Used      Available  Use%
hdfs://hadoop101.yinzhengjie.org.cn:9000  4980400128000  3477504  4976186191872    0%
[root@hadoop101.yinzhengjie.org.cn ~]# 
[root@hadoop101.yinzhengjie.org.cn ~]# hdfs dfs -df                    #默认以字节的形式显示当前集群的资源使用情况
[root@hadoop101.yinzhengjie.org.cn ~]# hdfs dfs -df -h
Filesystem                                 Size   Used  Available  Use%
hdfs://hadoop101.yinzhengjie.org.cn:9000  4.5 T  3.3 M      4.5 T    0%
[root@hadoop101.yinzhengjie.org.cn ~]# 
[root@hadoop101.yinzhengjie.org.cn ~]# hdfs dfs -df -h                  #以人性化的方式显示当前集群的资源使用情况

4>.查看某个文本文件的内容

[root@hadoop101.yinzhengjie.org.cn ~]# hdfs dfs  -ls /
Found 6 items
-rw-r--r--   3 root supergroup        433 2020-03-16 09:14 /hosts
drwxr-xr-x   - root supergroup          0 2020-03-12 19:20 /inputDir
drwxr-xr-x   - root supergroup          0 2020-03-12 19:20 /outputDir
drwxrwx---   - root supergroup          0 2020-03-12 19:20 /tmp
drwxrwx---   - root supergroup          0 2020-03-12 16:51 /yinzhengjie
drwxr-xr-x   - root supergroup          0 2020-03-16 09:16 /yum.repos.d
[root@hadoop101.yinzhengjie.org.cn ~]# 
[root@hadoop101.yinzhengjie.org.cn ~]# 
[root@hadoop101.yinzhengjie.org.cn ~]# hdfs dfs  -cat /hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6

#Hadoop cluster
172.200.4.101 hadoop101.yinzhengjie.org.cn
172.200.4.102 hadoop102.yinzhengjie.org.cn
172.200.4.103 hadoop103.yinzhengjie.org.cn
172.200.4.104 hadoop104.yinzhengjie.org.cn
172.200.4.105 hadoop105.yinzhengjie.org.cn
172.200.4.106 hadoop106.yinzhengjie.org.cn
[root@hadoop101.yinzhengjie.org.cn ~]# 
[root@hadoop101.yinzhengjie.org.cn ~]# 
[root@hadoop101.yinzhengjie.org.cn ~]# hdfs dfs -cat /hosts                #查看"/hosts"文件内容
[root@hadoop101.yinzhengjie.org.cn ~]# hdfs dfs  -ls /
Found 6 items
-rw-r--r--   3 root supergroup        433 2020-03-16 09:14 /hosts
drwxr-xr-x   - root supergroup          0 2020-03-12 19:20 /inputDir
drwxr-xr-x   - root supergroup          0 2020-03-12 19:20 /outputDir
drwxrwx---   - root supergroup          0 2020-03-12 19:20 /tmp
drwxrwx---   - root supergroup          0 2020-03-12 16:51 /yinzhengjie
drwxr-xr-x   - root supergroup          0 2020-03-16 09:16 /yum.repos.d
[root@hadoop101.yinzhengjie.org.cn ~]# 
[root@hadoop101.yinzhengjie.org.cn ~]# hdfs dfs  -text /hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6

#Hadoop cluster
172.200.4.101 hadoop101.yinzhengjie.org.cn
172.200.4.102 hadoop102.yinzhengjie.org.cn
172.200.4.103 hadoop103.yinzhengjie.org.cn
172.200.4.104 hadoop104.yinzhengjie.org.cn
172.200.4.105 hadoop105.yinzhengjie.org.cn
172.200.4.106 hadoop106.yinzhengjie.org.cn
[root@hadoop101.yinzhengjie.org.cn ~]# 
[root@hadoop101.yinzhengjie.org.cn ~]# hdfs dfs -text /hosts                #同上,也是查看文本文件内容

5>.删除某个文件或目录

[root@hadoop101.yinzhengjie.org.cn ~]# hdfs dfs  -ls /
Found 5 items
-rw-r--r--   3 root supergroup        433 2020-03-16 09:14 /hosts
drwxr-xr-x   - root supergroup          0 2020-03-12 19:20 /inputDir
drwxr-xr-x   - root supergroup          0 2020-03-12 19:20 /outputDir
drwxrwx---   - root supergroup          0 2020-03-12 19:20 /tmp
drwxrwx---   - root supergroup          0 2020-03-12 16:51 /yinzhengjie
[root@hadoop101.yinzhengjie.org.cn ~]# 
[root@hadoop101.yinzhengjie.org.cn ~]# 
[root@hadoop101.yinzhengjie.org.cn ~]# hdfs dfs  -rm  /hosts
Deleted /hosts
[root@hadoop101.yinzhengjie.org.cn ~]# 
[root@hadoop101.yinzhengjie.org.cn ~]# hdfs dfs  -ls /
Found 4 items
drwxr-xr-x   - root supergroup          0 2020-03-12 19:20 /inputDir
drwxr-xr-x   - root supergroup          0 2020-03-12 19:20 /outputDir
drwxrwx---   - root supergroup          0 2020-03-12 19:20 /tmp
drwxrwx---   - root supergroup          0 2020-03-12 16:51 /yinzhengjie
[root@hadoop101.yinzhengjie.org.cn ~]# 
[root@hadoop101.yinzhengjie.org.cn ~]# hdfs dfs -rm /hosts                   #删除根目录下的"hosts"文件
[root@hadoop101.yinzhengjie.org.cn ~]# hdfs dfs  -ls /
Found 6 items
-rw-r--r--   3 root supergroup        433 2020-03-16 09:14 /hosts
drwxr-xr-x   - root supergroup          0 2020-03-12 19:20 /inputDir
drwxr-xr-x   - root supergroup          0 2020-03-12 19:20 /outputDir
drwxrwx---   - root supergroup          0 2020-03-12 19:20 /tmp
drwxrwx---   - root supergroup          0 2020-03-12 16:51 /yinzhengjie
drwxr-xr-x   - root supergroup          0 2020-03-16 09:16 /yum.repos.d
[root@hadoop101.yinzhengjie.org.cn ~]# 
[root@hadoop101.yinzhengjie.org.cn ~]# 
[root@hadoop101.yinzhengjie.org.cn ~]# hdfs dfs -rm -r /yum.repos.d
Deleted /yum.repos.d
[root@hadoop101.yinzhengjie.org.cn ~]# 
[root@hadoop101.yinzhengjie.org.cn ~]# hdfs dfs  -ls /
Found 5 items
-rw-r--r--   3 root supergroup        433 2020-03-16 09:14 /hosts
drwxr-xr-x   - root supergroup          0 2020-03-12 19:20 /inputDir
drwxr-xr-x   - root supergroup          0 2020-03-12 19:20 /outputDir
drwxrwx---   - root supergroup          0 2020-03-12 19:20 /tmp
drwxrwx---   - root supergroup          0 2020-03-12 16:51 /yinzhengjie
[root@hadoop101.yinzhengjie.org.cn ~]# 
[root@hadoop101.yinzhengjie.org.cn ~]# 
[root@hadoop101.yinzhengjie.org.cn ~]# hdfs dfs -rm -r /yum.repos.d              #删除根目录下的"yum.repo.d"目录
[root@hadoop101.yinzhengjie.org.cn ~]# 
[root@hadoop101.yinzhengjie.org.cn ~]# hdfs dfs -ls /
Found 5 items
-rw-r--r--   3 root supergroup        433 2020-03-16 09:42 /HOSTS
drwxr-xr-x   - root supergroup          0 2020-03-12 19:20 /inputDir
drwxr-xr-x   - root supergroup          0 2020-03-12 19:20 /output
drwxrwx---   - root supergroup          0 2020-03-12 19:20 /tmp
drwxrwx---   - root supergroup          0 2020-03-12 16:51 /yinzhengjie
[root@hadoop101.yinzhengjie.org.cn ~]# 
[root@hadoop101.yinzhengjie.org.cn ~]# hdfs dfs -rm -r /HOSTS /inputDir /output
Deleted /HOSTS
Deleted /inputDir
Deleted /output
[root@hadoop101.yinzhengjie.org.cn ~]# 
[root@hadoop101.yinzhengjie.org.cn ~]# hdfs dfs -ls /
Found 2 items
drwxrwx---   - root supergroup          0 2020-03-12 19:20 /tmp
drwxrwx---   - root supergroup          0 2020-03-12 16:51 /yinzhengjie
[root@hadoop101.yinzhengjie.org.cn ~]# 
[root@hadoop101.yinzhengjie.org.cn ~]# 
[root@hadoop101.yinzhengjie.org.cn ~]# hdfs dfs -rm -r /HOSTS /inputDir /output      #我们也可以一次性删除多个文件或目录
[root@hadoop101.yinzhengjie.org.cn ~]# hdfs dfs -ls /
Found 4 items
drwxr-xr-x   - root supergroup          0 2020-03-16 09:46 /bigdata
drwxr-xr-x   - root supergroup          0 2020-03-16 09:46 /etc
drwxrwx---   - root supergroup          0 2020-03-12 19:20 /tmp
drwxrwx---   - root supergroup          0 2020-03-12 16:51 /yinzhengjie
[root@hadoop101.yinzhengjie.org.cn ~]# 
[root@hadoop101.yinzhengjie.org.cn ~]# hdfs dfs -ls /bigdata
[root@hadoop101.yinzhengjie.org.cn ~]# 
[root@hadoop101.yinzhengjie.org.cn ~]# hdfs dfs -rmdir /bigdata
[root@hadoop101.yinzhengjie.org.cn ~]# 
[root@hadoop101.yinzhengjie.org.cn ~]# hdfs dfs -ls /
Found 3 items
drwxr-xr-x   - root supergroup          0 2020-03-16 09:46 /etc
drwxrwx---   - root supergroup          0 2020-03-12 19:20 /tmp
drwxrwx---   - root supergroup          0 2020-03-12 16:51 /yinzhengjie
[root@hadoop101.yinzhengjie.org.cn ~]# 
[root@hadoop101.yinzhengjie.org.cn ~]# hdfs dfs -ls /etc
Found 1 items
drwxr-xr-x   - root supergroup          0 2020-03-16 09:46 /etc/hadoop
[root@hadoop101.yinzhengjie.org.cn ~]# 
[root@hadoop101.yinzhengjie.org.cn ~]# hdfs dfs -rmdir /etc
rmdir: `/etc': Directory is not empty
[root@hadoop101.yinzhengjie.org.cn ~]# 
[root@hadoop101.yinzhengjie.org.cn ~]# hdfs dfs -rmdir /bigdata                #用于删除空目录,若删除的目录非空会删除失败

6>.重命名文件或目录

[root@hadoop101.yinzhengjie.org.cn ~]# hdfs dfs  -ls /
Found 5 items
-rw-r--r--   3 root supergroup        433 2020-03-16 09:37 /hosts
drwxr-xr-x   - root supergroup          0 2020-03-12 19:20 /inputDir
drwxr-xr-x   - root supergroup          0 2020-03-12 19:20 /outputDir
drwxrwx---   - root supergroup          0 2020-03-12 19:20 /tmp
drwxrwx---   - root supergroup          0 2020-03-12 16:51 /yinzhengjie
[root@hadoop101.yinzhengjie.org.cn ~]# 
[root@hadoop101.yinzhengjie.org.cn ~]# hdfs dfs -mv /outputDir /output
[root@hadoop101.yinzhengjie.org.cn ~]# 
[root@hadoop101.yinzhengjie.org.cn ~]# hdfs dfs  -ls /
Found 5 items
-rw-r--r--   3 root supergroup        433 2020-03-16 09:37 /hosts
drwxr-xr-x   - root supergroup          0 2020-03-12 19:20 /inputDir
drwxr-xr-x   - root supergroup          0 2020-03-12 19:20 /output
drwxrwx---   - root supergroup          0 2020-03-12 19:20 /tmp
drwxrwx---   - root supergroup          0 2020-03-12 16:51 /yinzhengjie
[root@hadoop101.yinzhengjie.org.cn ~]# 
[root@hadoop101.yinzhengjie.org.cn ~]# hdfs dfs -mv /outputDir /output            #将根目录下的"outputDir"目录重命名为"output"
[root@hadoop101.yinzhengjie.org.cn ~]# hdfs dfs  -ls /
Found 5 items
-rw-r--r--   3 root supergroup        433 2020-03-16 09:37 /hosts
drwxr-xr-x   - root supergroup          0 2020-03-12 19:20 /inputDir
drwxr-xr-x   - root supergroup          0 2020-03-12 19:20 /output
drwxrwx---   - root supergroup          0 2020-03-12 19:20 /tmp
drwxrwx---   - root supergroup          0 2020-03-12 16:51 /yinzhengjie
[root@hadoop101.yinzhengjie.org.cn ~]# 
[root@hadoop101.yinzhengjie.org.cn ~]# 
[root@hadoop101.yinzhengjie.org.cn ~]# hdfs dfs -mv /hosts /HOSTS
[root@hadoop101.yinzhengjie.org.cn ~]# 
[root@hadoop101.yinzhengjie.org.cn ~]# hdfs dfs  -ls /
Found 5 items
-rw-r--r--   3 root supergroup        433 2020-03-16 09:37 /HOSTS
drwxr-xr-x   - root supergroup          0 2020-03-12 19:20 /inputDir
drwxr-xr-x   - root supergroup          0 2020-03-12 19:20 /output
drwxrwx---   - root supergroup          0 2020-03-12 19:20 /tmp
drwxrwx---   - root supergroup          0 2020-03-12 16:51 /yinzhengjie
[root@hadoop101.yinzhengjie.org.cn ~]# 
[root@hadoop101.yinzhengjie.org.cn ~]# 
[root@hadoop101.yinzhengjie.org.cn ~]# hdfs dfs -mv /hosts /HOSTS               #将根目录下的"hosts"文件重命名为"HOSTS"文件

7>.创建目录

[root@hadoop101.yinzhengjie.org.cn ~]# hdfs dfs -ls /
Found 2 items
drwxrwx---   - root supergroup          0 2020-03-12 19:20 /tmp
drwxrwx---   - root supergroup          0 2020-03-12 16:51 /yinzhengjie
[root@hadoop101.yinzhengjie.org.cn ~]# 
[root@hadoop101.yinzhengjie.org.cn ~]# hdfs dfs -mkdir  /bigdata
[root@hadoop101.yinzhengjie.org.cn ~]# 
[root@hadoop101.yinzhengjie.org.cn ~]# hdfs dfs -ls /
Found 3 items
drwxr-xr-x   - root supergroup          0 2020-03-16 09:46 /bigdata
drwxrwx---   - root supergroup          0 2020-03-12 19:20 /tmp
drwxrwx---   - root supergroup          0 2020-03-12 16:51 /yinzhengjie
[root@hadoop101.yinzhengjie.org.cn ~]# 
[root@hadoop101.yinzhengjie.org.cn ~]# hdfs dfs -mkdir /bigdata                 #创建目录
[root@hadoop101.yinzhengjie.org.cn ~]# hdfs dfs -ls /
Found 3 items
drwxr-xr-x   - root supergroup          0 2020-03-16 09:46 /bigdata
drwxrwx---   - root supergroup          0 2020-03-12 19:20 /tmp
drwxrwx---   - root supergroup          0 2020-03-12 16:51 /yinzhengjie
[root@hadoop101.yinzhengjie.org.cn ~]# 
[root@hadoop101.yinzhengjie.org.cn ~]# hdfs dfs -mkdir -p /etc/hadoop
[root@hadoop101.yinzhengjie.org.cn ~]# 
[root@hadoop101.yinzhengjie.org.cn ~]# hdfs dfs -ls /
Found 4 items
drwxr-xr-x   - root supergroup          0 2020-03-16 09:46 /bigdata
drwxr-xr-x   - root supergroup          0 2020-03-16 09:46 /etc
drwxrwx---   - root supergroup          0 2020-03-12 19:20 /tmp
drwxrwx---   - root supergroup          0 2020-03-12 16:51 /yinzhengjie
[root@hadoop101.yinzhengjie.org.cn ~]# 
[root@hadoop101.yinzhengjie.org.cn ~]# hdfs dfs -ls /etc
Found 1 items
drwxr-xr-x   - root supergroup          0 2020-03-16 09:46 /etc/hadoop
[root@hadoop101.yinzhengjie.org.cn ~]# 
[root@hadoop101.yinzhengjie.org.cn ~]# hdfs dfs -ls /etc/hadoop
[root@hadoop101.yinzhengjie.org.cn ~]# 
[root@hadoop101.yinzhengjie.org.cn ~]# 
[root@hadoop101.yinzhengjie.org.cn ~]# hdfs dfs -mkdir -p /etc/hadoop              #递归创建目录

8>.创建文件

[root@hadoop101.yinzhengjie.org.cn ~]# hdfs dfs -ls /
Found 3 items
drwxr-xr-x   - root supergroup          0 2020-03-16 09:46 /etc
drwxrwx---   - root supergroup          0 2020-03-12 19:20 /tmp
drwxrwx---   - root supergroup          0 2020-03-12 16:51 /yinzhengjie
[root@hadoop101.yinzhengjie.org.cn ~]# 
[root@hadoop101.yinzhengjie.org.cn ~]# hdfs dfs -touchz /bigdata.log
[root@hadoop101.yinzhengjie.org.cn ~]# 
[root@hadoop101.yinzhengjie.org.cn ~]# hdfs dfs -ls /
Found 4 items
-rw-r--r--   3 root supergroup          0 2020-03-16 09:59 /bigdata.log
drwxr-xr-x   - root supergroup          0 2020-03-16 09:46 /etc
drwxrwx---   - root supergroup          0 2020-03-12 19:20 /tmp
drwxrwx---   - root supergroup          0 2020-03-12 16:51 /yinzhengjie
[root@hadoop101.yinzhengjie.org.cn ~]# 
[root@hadoop101.yinzhengjie.org.cn ~]# 
[root@hadoop101.yinzhengjie.org.cn ~]# hdfs dfs -touchz /bigdata.log                #在根目录下创建bigdata.log文件

9>.修改目录或文件的权限

[root@hadoop101.yinzhengjie.org.cn ~]# hdfs dfs -ls /
Found 3 items
drwxr-xr-x   - root supergroup          0 2020-03-16 09:46 /etc
drwxrwx---   - root supergroup          0 2020-03-12 19:20 /tmp
drwxrwx---   - root supergroup          0 2020-03-12 16:51 /yinzhengjie
[root@hadoop101.yinzhengjie.org.cn ~]# 
[root@hadoop101.yinzhengjie.org.cn ~]# hdfs dfs -chmod o+x /yinzhengjie
[root@hadoop101.yinzhengjie.org.cn ~]# 
[root@hadoop101.yinzhengjie.org.cn ~]# hdfs dfs -ls /
Found 3 items
drwxr-xr-x   - root supergroup          0 2020-03-16 09:46 /etc
drwxrwx---   - root supergroup          0 2020-03-12 19:20 /tmp
drwxrwx--x   - root supergroup          0 2020-03-12 16:51 /yinzhengjie
[root@hadoop101.yinzhengjie.org.cn ~]# 
[root@hadoop101.yinzhengjie.org.cn ~]# 
[root@hadoop101.yinzhengjie.org.cn ~]# hdfs dfs -chmod o+x /yinzhengjie              #为根目录下的yinzhengjie目录的其他人授权执行权限
[root@hadoop101.yinzhengjie.org.cn ~]# hdfs dfs -ls /
Found 3 items
drwxr-xr-x   - root supergroup          0 2020-03-16 09:46 /etc
drwxrwx---   - root supergroup          0 2020-03-12 19:20 /tmp
drwxrwx--x   - root supergroup          0 2020-03-12 16:51 /yinzhengjie
[root@hadoop101.yinzhengjie.org.cn ~]# 
[root@hadoop101.yinzhengjie.org.cn ~]# hdfs dfs -chmod o-x /yinzhengjie
[root@hadoop101.yinzhengjie.org.cn ~]# 
[root@hadoop101.yinzhengjie.org.cn ~]# hdfs dfs -ls /
Found 3 items
drwxr-xr-x   - root supergroup          0 2020-03-16 09:46 /etc
drwxrwx---   - root supergroup          0 2020-03-12 19:20 /tmp
drwxrwx---   - root supergroup          0 2020-03-12 16:51 /yinzhengjie
[root@hadoop101.yinzhengjie.org.cn ~]# 
[root@hadoop101.yinzhengjie.org.cn ~]# hdfs dfs -chmod o-x /yinzhengjie              #和上面的命令相反,回收根目录下的yinzhengjie目录的执行权限
[root@hadoop101.yinzhengjie.org.cn ~]# hdfs dfs -ls /
Found 3 items
drwxr-xr-x   - root supergroup          0 2020-03-16 09:46 /etc
drwxrwx---   - root supergroup          0 2020-03-12 19:20 /tmp
drwxrwx---   - root supergroup          0 2020-03-12 16:51 /yinzhengjie
[root@hadoop101.yinzhengjie.org.cn ~]# 
[root@hadoop101.yinzhengjie.org.cn ~]# hdfs dfs -chmod g-x /yinzhengjie
[root@hadoop101.yinzhengjie.org.cn ~]# 
[root@hadoop101.yinzhengjie.org.cn ~]# hdfs dfs -ls /
Found 3 items
drwxr-xr-x   - root supergroup          0 2020-03-16 09:46 /etc
drwxrwx---   - root supergroup          0 2020-03-12 19:20 /tmp
drwxrw----   - root supergroup          0 2020-03-12 16:51 /yinzhengjie
[root@hadoop101.yinzhengjie.org.cn ~]# 
[root@hadoop101.yinzhengjie.org.cn ~]# hdfs dfs -chmod g-x /yinzhengjie              #将组的所拥有的执行权限收回
[root@hadoop101.yinzhengjie.org.cn ~]# hdfs dfs -ls /
Found 3 items
drwxr-xr-x   - root supergroup          0 2020-03-16 09:46 /etc
drwxrwx---   - root supergroup          0 2020-03-12 19:20 /tmp
drwxrw----   - root supergroup          0 2020-03-12 16:51 /yinzhengjie
[root@hadoop101.yinzhengjie.org.cn ~]# 
[root@hadoop101.yinzhengjie.org.cn ~]# 
[root@hadoop101.yinzhengjie.org.cn ~]# hdfs dfs -chmod g+x /yinzhengjie
[root@hadoop101.yinzhengjie.org.cn ~]# 
[root@hadoop101.yinzhengjie.org.cn ~]# hdfs dfs -ls /
Found 3 items
drwxr-xr-x   - root supergroup          0 2020-03-16 09:46 /etc
drwxrwx---   - root supergroup          0 2020-03-12 19:20 /tmp
drwxrwx---   - root supergroup          0 2020-03-12 16:51 /yinzhengjie
[root@hadoop101.yinzhengjie.org.cn ~]# 
[root@hadoop101.yinzhengjie.org.cn ~]# hdfs dfs -chmod g+x /yinzhengjie              #为组用户添加执行权限
[root@hadoop101.yinzhengjie.org.cn ~]# hdfs dfs -ls /
Found 3 items
drwxr-xr-x   - root supergroup          0 2020-03-16 09:46 /etc
drwxrwx---   - root supergroup          0 2020-03-12 19:20 /tmp
drwxrwx---   - root supergroup          0 2020-03-12 16:51 /yinzhengjie
[root@hadoop101.yinzhengjie.org.cn ~]# 
[root@hadoop101.yinzhengjie.org.cn ~]# hdfs dfs -chmod u-w /yinzhengjie
[root@hadoop101.yinzhengjie.org.cn ~]# 
[root@hadoop101.yinzhengjie.org.cn ~]# hdfs dfs -ls /
Found 3 items
drwxr-xr-x   - root supergroup          0 2020-03-16 09:46 /etc
drwxrwx---   - root supergroup          0 2020-03-12 19:20 /tmp
dr-xrwx---   - root supergroup          0 2020-03-12 16:51 /yinzhengjie
[root@hadoop101.yinzhengjie.org.cn ~]# 
[root@hadoop101.yinzhengjie.org.cn ~]# 
[root@hadoop101.yinzhengjie.org.cn ~]# hdfs dfs -chmod u-w /yinzhengjie              #将拥有者的写入权限收回
[root@hadoop101.yinzhengjie.org.cn ~]# hdfs dfs -ls /
Found 3 items
drwxr-xr-x   - root supergroup          0 2020-03-16 09:46 /etc
drwxrwx---   - root supergroup          0 2020-03-12 19:20 /tmp
dr-xrwx---   - root supergroup          0 2020-03-12 16:51 /yinzhengjie
[root@hadoop101.yinzhengjie.org.cn ~]# 
[root@hadoop101.yinzhengjie.org.cn ~]# 
[root@hadoop101.yinzhengjie.org.cn ~]# hdfs dfs -chmod u+w /yinzhengjie
[root@hadoop101.yinzhengjie.org.cn ~]# 
[root@hadoop101.yinzhengjie.org.cn ~]# hdfs dfs -ls /
Found 3 items
drwxr-xr-x   - root supergroup          0 2020-03-16 09:46 /etc
drwxrwx---   - root supergroup          0 2020-03-12 19:20 /tmp
drwxrwx---   - root supergroup          0 2020-03-12 16:51 /yinzhengjie
[root@hadoop101.yinzhengjie.org.cn ~]# 
[root@hadoop101.yinzhengjie.org.cn ~]# 
[root@hadoop101.yinzhengjie.org.cn ~]# hdfs dfs -chmod u+w /yinzhengjie              #为拥有者添加写入权限
[root@hadoop101.yinzhengjie.org.cn ~]# hdfs dfs -ls /
Found 4 items
-rw-r--r--   3 root supergroup          0 2020-03-16 09:59 /bigdata.log
drwxr-xr-x   - root supergroup          0 2020-03-16 09:46 /etc
drwxrwx---   - root supergroup          0 2020-03-12 19:20 /tmp
drwxrwx---   - root supergroup          0 2020-03-12 16:51 /yinzhengjie
[root@hadoop101.yinzhengjie.org.cn ~]# 
[root@hadoop101.yinzhengjie.org.cn ~]# 
[root@hadoop101.yinzhengjie.org.cn ~]# hdfs dfs -chmod g+w /bigdata.log
[root@hadoop101.yinzhengjie.org.cn ~]# 
[root@hadoop101.yinzhengjie.org.cn ~]# hdfs dfs -ls /
Found 4 items
-rw-rw-r--   3 root supergroup          0 2020-03-16 09:59 /bigdata.log
drwxr-xr-x   - root supergroup          0 2020-03-16 09:46 /etc
drwxrwx---   - root supergroup          0 2020-03-12 19:20 /tmp
drwxrwx---   - root supergroup          0 2020-03-12 16:51 /yinzhengjie
[root@hadoop101.yinzhengjie.org.cn ~]# 
[root@hadoop101.yinzhengjie.org.cn ~]# hdfs dfs -chmod g+w /bigdata.log              #为文件的所属组添加写入权限

10>.修改文件或目录所属组的权限

[root@hadoop101.yinzhengjie.org.cn ~]# hdfs dfs -ls /
Found 4 items
-rw-rw-r--   3 root supergroup          0 2020-03-16 09:59 /bigdata.log
drwxr-xr-x   - root supergroup          0 2020-03-16 09:46 /etc
drwxrwx---   - root supergroup          0 2020-03-12 19:20 /tmp
drwxrwx---   - root supergroup          0 2020-03-12 16:51 /yinzhengjie
[root@hadoop101.yinzhengjie.org.cn ~]# 
[root@hadoop101.yinzhengjie.org.cn ~]# hdfs dfs -chgrp yinzhengjie /bigdata.log
[root@hadoop101.yinzhengjie.org.cn ~]# 
[root@hadoop101.yinzhengjie.org.cn ~]# hdfs dfs -ls /
Found 4 items
-rw-rw-r--   3 root yinzhengjie          0 2020-03-16 09:59 /bigdata.log
drwxr-xr-x   - root supergroup           0 2020-03-16 09:46 /etc
drwxrwx---   - root supergroup           0 2020-03-12 19:20 /tmp
drwxrwx---   - root supergroup           0 2020-03-12 16:51 /yinzhengjie
[root@hadoop101.yinzhengjie.org.cn ~]# 
[root@hadoop101.yinzhengjie.org.cn ~]# 
[root@hadoop101.yinzhengjie.org.cn ~]# hdfs dfs -chgrp yinzhengjie /bigdata.log          #修改文件的所属组权限
[root@hadoop101.yinzhengjie.org.cn ~]# hdfs dfs -ls /
Found 4 items
-rw-rw-r--   3 root yinzhengjie          0 2020-03-16 09:59 /bigdata.log
drwxr-xr-x   - root supergroup           0 2020-03-16 09:46 /etc
drwxrwx---   - root supergroup           0 2020-03-12 19:20 /tmp
drwxrwx---   - root supergroup           0 2020-03-12 16:51 /yinzhengjie
[root@hadoop101.yinzhengjie.org.cn ~]# 
[root@hadoop101.yinzhengjie.org.cn ~]# hdfs dfs -ls /etc
Found 1 items
drwxr-xr-x   - root supergroup          0 2020-03-16 09:46 /etc/hadoop
[root@hadoop101.yinzhengjie.org.cn ~]# 
[root@hadoop101.yinzhengjie.org.cn ~]# hdfs dfs -ls /
Found 4 items
-rw-rw-r--   3 root yinzhengjie          0 2020-03-16 09:59 /bigdata.log
drwxr-xr-x   - root supergroup           0 2020-03-16 09:46 /etc
drwxrwx---   - root supergroup           0 2020-03-12 19:20 /tmp
drwxrwx---   - root supergroup           0 2020-03-12 16:51 /yinzhengjie
[root@hadoop101.yinzhengjie.org.cn ~]# 
[root@hadoop101.yinzhengjie.org.cn ~]# hdfs dfs -chgrp -R yinzhengjie /etc
[root@hadoop101.yinzhengjie.org.cn ~]# 
[root@hadoop101.yinzhengjie.org.cn ~]# hdfs dfs -ls /
Found 4 items
-rw-rw-r--   3 root yinzhengjie          0 2020-03-16 09:59 /bigdata.log
drwxr-xr-x   - root yinzhengjie          0 2020-03-16 09:46 /etc
drwxrwx---   - root supergroup           0 2020-03-12 19:20 /tmp
drwxrwx---   - root supergroup           0 2020-03-12 16:51 /yinzhengjie
[root@hadoop101.yinzhengjie.org.cn ~]# 
[root@hadoop101.yinzhengjie.org.cn ~]# hdfs dfs -ls /etc
Found 1 items
drwxr-xr-x   - root yinzhengjie          0 2020-03-16 09:46 /etc/hadoop
[root@hadoop101.yinzhengjie.org.cn ~]# 
[root@hadoop101.yinzhengjie.org.cn ~]# hdfs dfs -chgrp -R yinzhengjie /etc             #递归修改所述组的权限
[root@hadoop101.yinzhengjie.org.cn ~]# 
[root@hadoop101.yinzhengjie.org.cn ~]# hdfs dfs -ls /
Found 4 items
-rw-rw-r--   3 root yinzhengjie          0 2020-03-16 09:59 /bigdata.log
drwxr-xr-x   - root yinzhengjie          0 2020-03-16 09:46 /etc
drwxrwx---   - root supergroup           0 2020-03-12 19:20 /tmp
drwxrwx---   - root supergroup           0 2020-03-12 16:51 /yinzhengjie
[root@hadoop101.yinzhengjie.org.cn ~]# 
[root@hadoop101.yinzhengjie.org.cn ~]# hdfs dfs -chown yinzhengjie:root /yinzhengjie/
[root@hadoop101.yinzhengjie.org.cn ~]# 
[root@hadoop101.yinzhengjie.org.cn ~]# hdfs dfs -ls /
Found 4 items
-rw-rw-r--   3 root        yinzhengjie          0 2020-03-16 09:59 /bigdata.log
drwxr-xr-x   - root        yinzhengjie          0 2020-03-16 09:46 /etc
drwxrwx---   - root        supergroup           0 2020-03-12 19:20 /tmp
drwxrwx---   - yinzhengjie root                 0 2020-03-12 16:51 /yinzhengjie
[root@hadoop101.yinzhengjie.org.cn ~]# 
[root@hadoop101.yinzhengjie.org.cn ~]# hdfs dfs -ls /yinzhengjie
Found 1 items
drwxrwx---   - root supergroup          0 2020-03-12 16:51 /yinzhengjie/jobhistory
[root@hadoop101.yinzhengjie.org.cn ~]# 
[root@hadoop101.yinzhengjie.org.cn ~]# 
[root@hadoop101.yinzhengjie.org.cn ~]# hdfs dfs -chown yinzhengjie:root /yinzhengjie/      #修改当前目录的所有者及所有者的权限
[root@hadoop101.yinzhengjie.org.cn ~]# hdfs dfs -ls /
Found 4 items
-rw-rw-r--   3 root        yinzhengjie          0 2020-03-16 09:59 /bigdata.log
drwxr-xr-x   - root        yinzhengjie          0 2020-03-16 09:46 /etc
drwxrwx---   - root        supergroup           0 2020-03-12 19:20 /tmp
drwxrwx---   - yinzhengjie root                 0 2020-03-12 16:51 /yinzhengjie
[root@hadoop101.yinzhengjie.org.cn ~]# 
[root@hadoop101.yinzhengjie.org.cn ~]# hdfs dfs -ls /yinzhengjie
Found 1 items
drwxrwx---   - root supergroup          0 2020-03-12 16:51 /yinzhengjie/jobhistory
[root@hadoop101.yinzhengjie.org.cn ~]# 
[root@hadoop101.yinzhengjie.org.cn ~]# 
[root@hadoop101.yinzhengjie.org.cn ~]# hdfs dfs -chown -R root:yinzhengjie /yinzhengjie/
[root@hadoop101.yinzhengjie.org.cn ~]# 
[root@hadoop101.yinzhengjie.org.cn ~]# hdfs dfs -ls /yinzhengjie
Found 1 items
drwxrwx---   - root yinzhengjie          0 2020-03-12 16:51 /yinzhengjie/jobhistory
[root@hadoop101.yinzhengjie.org.cn ~]# 
[root@hadoop101.yinzhengjie.org.cn ~]# hdfs dfs -ls /
Found 4 items
-rw-rw-r--   3 root yinzhengjie          0 2020-03-16 09:59 /bigdata.log
drwxr-xr-x   - root yinzhengjie          0 2020-03-16 09:46 /etc
drwxrwx---   - root supergroup           0 2020-03-12 19:20 /tmp
drwxrwx---   - root yinzhengjie          0 2020-03-12 16:51 /yinzhengjie
[root@hadoop101.yinzhengjie.org.cn ~]# 
[root@hadoop101.yinzhengjie.org.cn ~]# hdfs dfs -chown -R root:yinzhengjie /yinzhengjie/    #递归修改所属主和所属组的权限

11>.修改文件或目录的名称

[root@hadoop101.yinzhengjie.org.cn ~]# hdfs dfs -ls /
Found 4 items
-rw-rw-r--   3 root yinzhengjie          0 2020-03-16 09:59 /bigdata.log
drwxr-xr-x   - root yinzhengjie          0 2020-03-16 09:46 /etc
drwxrwx---   - root supergroup           0 2020-03-12 19:20 /tmp
drwxrwx---   - root yinzhengjie          0 2020-03-12 16:51 /yinzhengjie
[root@hadoop101.yinzhengjie.org.cn ~]# 
[root@hadoop101.yinzhengjie.org.cn ~]# hdfs dfs -mv /yinzhengjie /yinzhengjie2020
[root@hadoop101.yinzhengjie.org.cn ~]# 
[root@hadoop101.yinzhengjie.org.cn ~]# hdfs dfs -ls /
Found 4 items
-rw-rw-r--   3 root yinzhengjie          0 2020-03-16 09:59 /bigdata.log
drwxr-xr-x   - root yinzhengjie          0 2020-03-16 09:46 /etc
drwxrwx---   - root supergroup           0 2020-03-12 19:20 /tmp
drwxrwx---   - root yinzhengjie          0 2020-03-12 16:51 /yinzhengjie2020
[root@hadoop101.yinzhengjie.org.cn ~]# 
[root@hadoop101.yinzhengjie.org.cn ~]# 
[root@hadoop101.yinzhengjie.org.cn ~]# hdfs dfs -mv /yinzhengjie /yinzhengjie2020         #修改目录名称
[root@hadoop101.yinzhengjie.org.cn ~]# hdfs dfs -ls /
Found 4 items
-rw-rw-r--   3 root yinzhengjie          0 2020-03-16 09:59 /bigdata.log
drwxr-xr-x   - root yinzhengjie          0 2020-03-16 09:46 /etc
drwxrwx---   - root supergroup           0 2020-03-12 19:20 /tmp
drwxrwx---   - root yinzhengjie          0 2020-03-12 16:51 /yinzhengjie2020
[root@hadoop101.yinzhengjie.org.cn ~]# 
[root@hadoop101.yinzhengjie.org.cn ~]# hdfs dfs -mv /bigdata.log /bigdata.txt
[root@hadoop101.yinzhengjie.org.cn ~]# 
[root@hadoop101.yinzhengjie.org.cn ~]# hdfs dfs -ls /
Found 4 items
-rw-rw-r--   3 root yinzhengjie          0 2020-03-16 09:59 /bigdata.txt
drwxr-xr-x   - root yinzhengjie          0 2020-03-16 09:46 /etc
drwxrwx---   - root supergroup           0 2020-03-12 19:20 /tmp
drwxrwx---   - root yinzhengjie          0 2020-03-12 16:51 /yinzhengjie2020
[root@hadoop101.yinzhengjie.org.cn ~]# 
[root@hadoop101.yinzhengjie.org.cn ~]# hdfs dfs -mv /bigdata.log /bigdata.txt           #修改文件名称

12>.拷贝文件或目录

[root@hadoop101.yinzhengjie.org.cn ~]# hdfs dfs -ls /
Found 4 items
-rw-rw-r--   3 root yinzhengjie          0 2020-03-16 09:59 /bigdata.txt
drwxr-xr-x   - root yinzhengjie          0 2020-03-16 09:46 /etc
drwxrwx---   - root supergroup           0 2020-03-12 19:20 /tmp
drwxrwx---   - root yinzhengjie          0 2020-03-12 16:51 /yinzhengjie2020
[root@hadoop101.yinzhengjie.org.cn ~]# 
[root@hadoop101.yinzhengjie.org.cn ~]# hdfs dfs -cp /bigdata.txt /bigdata.log
[root@hadoop101.yinzhengjie.org.cn ~]# 
[root@hadoop101.yinzhengjie.org.cn ~]# hdfs dfs -ls /
Found 5 items
-rw-r--r--   3 root supergroup           0 2020-03-16 10:13 /bigdata.log
-rw-rw-r--   3 root yinzhengjie          0 2020-03-16 09:59 /bigdata.txt
drwxr-xr-x   - root yinzhengjie          0 2020-03-16 09:46 /etc
drwxrwx---   - root supergroup           0 2020-03-12 19:20 /tmp
drwxrwx---   - root yinzhengjie          0 2020-03-12 16:51 /yinzhengjie2020
[root@hadoop101.yinzhengjie.org.cn ~]# 
[root@hadoop101.yinzhengjie.org.cn ~]# hdfs dfs -cp /bigdata.txt /bigdata.log          #拷贝文件
[root@hadoop101.yinzhengjie.org.cn ~]# hdfs dfs -ls /
Found 5 items
-rw-r--r--   3 root supergroup           0 2020-03-16 10:13 /bigdata.log
-rw-rw-r--   3 root yinzhengjie          0 2020-03-16 09:59 /bigdata.txt
drwxr-xr-x   - root yinzhengjie          0 2020-03-16 09:46 /etc
drwxrwx---   - root supergroup           0 2020-03-12 19:20 /tmp
drwxrwx---   - root yinzhengjie          0 2020-03-12 16:51 /yinzhengjie2020
[root@hadoop101.yinzhengjie.org.cn ~]# 
[root@hadoop101.yinzhengjie.org.cn ~]# hdfs dfs -ls /yinzhengjie2020
Found 1 items
drwxrwx---   - root yinzhengjie          0 2020-03-12 16:51 /yinzhengjie2020/jobhistory
[root@hadoop101.yinzhengjie.org.cn ~]# 
[root@hadoop101.yinzhengjie.org.cn ~]# hdfs dfs -cp /yinzhengjie2020 /yinzhengjie
[root@hadoop101.yinzhengjie.org.cn ~]# 
[root@hadoop101.yinzhengjie.org.cn ~]# hdfs dfs -ls /
Found 6 items
-rw-r--r--   3 root supergroup           0 2020-03-16 10:13 /bigdata.log
-rw-rw-r--   3 root yinzhengjie          0 2020-03-16 09:59 /bigdata.txt
drwxr-xr-x   - root yinzhengjie          0 2020-03-16 09:46 /etc
drwxrwx---   - root supergroup           0 2020-03-12 19:20 /tmp
drwxr-xr-x   - root supergroup           0 2020-03-16 10:14 /yinzhengjie
drwxrwx---   - root yinzhengjie          0 2020-03-12 16:51 /yinzhengjie2020
[root@hadoop101.yinzhengjie.org.cn ~]# 
[root@hadoop101.yinzhengjie.org.cn ~]# hdfs dfs -ls /yinzhengjie/
Found 1 items
drwxr-xr-x   - root supergroup          0 2020-03-16 10:14 /yinzhengjie/jobhistory
[root@hadoop101.yinzhengjie.org.cn ~]# 
[root@hadoop101.yinzhengjie.org.cn ~]# 
[root@hadoop101.yinzhengjie.org.cn ~]# hdfs dfs -cp /yinzhengjie2020 /yinzhengjie        #拷贝目录

13>.查看文件的校验和

[root@hadoop101.yinzhengjie.org.cn ~]# hdfs dfs -ls /
Found 6 items
-rw-r--r--   3 root supergroup           0 2020-03-16 10:13 /bigdata.log
-rw-rw-r--   3 root yinzhengjie          0 2020-03-16 09:59 /bigdata.txt
drwxr-xr-x   - root yinzhengjie          0 2020-03-16 09:46 /etc
drwxrwx---   - root supergroup           0 2020-03-12 19:20 /tmp
drwxr-xr-x   - root supergroup           0 2020-03-16 10:14 /yinzhengjie
drwxrwx---   - root yinzhengjie          0 2020-03-12 16:51 /yinzhengjie2020
[root@hadoop101.yinzhengjie.org.cn ~]# 
[root@hadoop101.yinzhengjie.org.cn ~]# 
[root@hadoop101.yinzhengjie.org.cn ~]# hdfs dfs -checksum /bigdata.log
/bigdata.log    MD5-of-0MD5-of-0CRC32    00000000000000000000000070bc8f4b72a86921468bf8e8441dce51
[root@hadoop101.yinzhengjie.org.cn ~]# 
[root@hadoop101.yinzhengjie.org.cn ~]# hdfs dfs -checksum /bigdata.log

14>.设置HDFS中文件的副本数量

[root@hadoop101.yinzhengjie.org.cn ~]# hdfs dfs -ls /
Found 4 items
-rw-r--r--   3 root supergroup         433 2020-03-16 10:27 /hosts
drwxrwx---   - root supergroup           0 2020-03-12 19:20 /tmp
drwxrwx---   - root yinzhengjie          0 2020-03-12 16:51 /yinzhengjie2020
drwxr-xr-x   - root supergroup           0 2020-03-16 10:28 /yum.repos.d
[root@hadoop101.yinzhengjie.org.cn ~]# 
[root@hadoop101.yinzhengjie.org.cn ~]# hdfs dfs -setrep 2 /hosts
Replication 2 set: /hosts
[root@hadoop101.yinzhengjie.org.cn ~]# 
[root@hadoop101.yinzhengjie.org.cn ~]# hdfs dfs -ls /
Found 4 items
-rw-r--r--   2 root supergroup         433 2020-03-16 10:27 /hosts
drwxrwx---   - root supergroup           0 2020-03-12 19:20 /tmp
drwxrwx---   - root yinzhengjie          0 2020-03-12 16:51 /yinzhengjie2020
drwxr-xr-x   - root supergroup           0 2020-03-16 10:28 /yum.repos.d
[root@hadoop101.yinzhengjie.org.cn ~]# 
[root@hadoop101.yinzhengjie.org.cn ~]# 
[root@hadoop101.yinzhengjie.org.cn ~]# hdfs dfs -setrep 2 /hosts                  #将根目录下的"hosts"文件的副本数设置为2
[root@hadoop101.yinzhengjie.org.cn ~]# hdfs dfs -ls /yinzhengjie2020/jobhistory/manager/2020/03/12/000000
Found 6 items
-rwxrwx---   3 root yinzhengjie      33731 2020-03-12 16:54 /yinzhengjie2020/jobhistory/manager/2020/03/12/000000/job_1584002509171_0001-1584003247341-root-word+count-1584003263906-1-1-SUCCEEDED-default-1584003252477.jhist
-rwxrwx---   3 root yinzhengjie     202992 2020-03-12 16:54 /yinzhengjie2020/jobhistory/manager/2020/03/12/000000/job_1584002509171_0001_conf.xml
-rwxrwx---   3 root yinzhengjie      33735 2020-03-12 19:09 /yinzhengjie2020/jobhistory/manager/2020/03/12/000000/job_1584010951301_0001-1584011344282-root-word+count-1584011360241-1-1-SUCCEEDED-default-1584011349879.jhist
-rwxrwx---   3 root yinzhengjie     202988 2020-03-12 19:09 /yinzhengjie2020/jobhistory/manager/2020/03/12/000000/job_1584010951301_0001_conf.xml
-rwxrwx---   3 root yinzhengjie      33732 2020-03-12 19:20 /yinzhengjie2020/jobhistory/manager/2020/03/12/000000/job_1584011863930_0001-1584012039874-root-word+count-1584012056179-1-1-SUCCEEDED-default-1584012045689.jhist
-rwxrwx---   3 root yinzhengjie     202988 2020-03-12 19:20 /yinzhengjie2020/jobhistory/manager/2020/03/12/000000/job_1584011863930_0001_conf.xml
[root@hadoop101.yinzhengjie.org.cn ~]# 
[root@hadoop101.yinzhengjie.org.cn ~]# hdfs dfs -setrep -R 2 /yinzhengjie2020
Replication 2 set: /yinzhengjie2020/jobhistory/manager/2020/03/12/000000/job_1584002509171_0001-1584003247341-root-word+count-1584003263906-1-1-SUCCEEDED-default-1584003252477.jhist
Replication 2 set: /yinzhengjie2020/jobhistory/manager/2020/03/12/000000/job_1584002509171_0001_conf.xml
Replication 2 set: /yinzhengjie2020/jobhistory/manager/2020/03/12/000000/job_1584010951301_0001-1584011344282-root-word+count-1584011360241-1-1-SUCCEEDED-default-1584011349879.jhist
Replication 2 set: /yinzhengjie2020/jobhistory/manager/2020/03/12/000000/job_1584010951301_0001_conf.xml
Replication 2 set: /yinzhengjie2020/jobhistory/manager/2020/03/12/000000/job_1584011863930_0001-1584012039874-root-word+count-1584012056179-1-1-SUCCEEDED-default-1584012045689.jhist
Replication 2 set: /yinzhengjie2020/jobhistory/manager/2020/03/12/000000/job_1584011863930_0001_conf.xml
[root@hadoop101.yinzhengjie.org.cn ~]# 
[root@hadoop101.yinzhengjie.org.cn ~]# hdfs dfs -ls /yinzhengjie2020/jobhistory/manager/2020/03/12/000000
Found 6 items
-rwxrwx---   2 root yinzhengjie      33731 2020-03-12 16:54 /yinzhengjie2020/jobhistory/manager/2020/03/12/000000/job_1584002509171_0001-1584003247341-root-word+count-1584003263906-1-1-SUCCEEDED-default-1584003252477.jhist
-rwxrwx---   2 root yinzhengjie     202992 2020-03-12 16:54 /yinzhengjie2020/jobhistory/manager/2020/03/12/000000/job_1584002509171_0001_conf.xml
-rwxrwx---   2 root yinzhengjie      33735 2020-03-12 19:09 /yinzhengjie2020/jobhistory/manager/2020/03/12/000000/job_1584010951301_0001-1584011344282-root-word+count-1584011360241-1-1-SUCCEEDED-default-1584011349879.jhist
-rwxrwx---   2 root yinzhengjie     202988 2020-03-12 19:09 /yinzhengjie2020/jobhistory/manager/2020/03/12/000000/job_1584010951301_0001_conf.xml
-rwxrwx---   2 root yinzhengjie      33732 2020-03-12 19:20 /yinzhengjie2020/jobhistory/manager/2020/03/12/000000/job_1584011863930_0001-1584012039874-root-word+count-1584012056179-1-1-SUCCEEDED-default-1584012045689.jhist
-rwxrwx---   2 root yinzhengjie     202988 2020-03-12 19:20 /yinzhengjie2020/jobhistory/manager/2020/03/12/000000/job_1584011863930_0001_conf.xml
[root@hadoop101.yinzhengjie.org.cn ~]# 
[root@hadoop101.yinzhengjie.org.cn ~]# 
[root@hadoop101.yinzhengjie.org.cn ~]# hdfs dfs -setrep -R 2 /yinzhengjie2020          #递归将根目录下的"yinzhengjie2020"目录下所有的文件的副本数设置为2

15>.下载文件到本地

[root@hadoop101.yinzhengjie.org.cn ~]# hdfs dfs -ls /
Found 6 items
-rw-r--r--   3 root supergroup           0 2020-03-16 10:13 /bigdata.log
-rw-rw-r--   3 root yinzhengjie          0 2020-03-16 09:59 /bigdata.txt
drwxr-xr-x   - root yinzhengjie          0 2020-03-16 09:46 /etc
drwxrwx---   - root supergroup           0 2020-03-12 19:20 /tmp
drwxr-xr-x   - root supergroup           0 2020-03-16 10:14 /yinzhengjie
drwxrwx---   - root yinzhengjie          0 2020-03-12 16:51 /yinzhengjie2020
[root@hadoop101.yinzhengjie.org.cn ~]# 
[root@hadoop101.yinzhengjie.org.cn ~]# ll
total 0
[root@hadoop101.yinzhengjie.org.cn ~]# 
[root@hadoop101.yinzhengjie.org.cn ~]# hdfs dfs -get /bigdata.log
[root@hadoop101.yinzhengjie.org.cn ~]# 
[root@hadoop101.yinzhengjie.org.cn ~]# ll
total 0
-rw-r--r-- 1 root root 0 Mar 16 10:21 bigdata.log
[root@hadoop101.yinzhengjie.org.cn ~]# 
[root@hadoop101.yinzhengjie.org.cn ~]# 
[root@hadoop101.yinzhengjie.org.cn ~]# hdfs dfs -get /bigdata.log          #下载根目录下的"bigdata.log"文件
[root@hadoop101.yinzhengjie.org.cn ~]# hdfs dfs -ls /
Found 4 items
-rw-r--r--   2 root supergroup         433 2020-03-16 10:27 /hosts
drwxrwx---   - root supergroup           0 2020-03-12 19:20 /tmp
drwxrwx---   - root yinzhengjie          0 2020-03-12 16:51 /yinzhengjie2020
drwxr-xr-x   - root supergroup           0 2020-03-16 10:28 /yum.repos.d
[root@hadoop101.yinzhengjie.org.cn ~]# 
[root@hadoop101.yinzhengjie.org.cn ~]# ll
total 0
[root@hadoop101.yinzhengjie.org.cn ~]# 
[root@hadoop101.yinzhengjie.org.cn ~]# hdfs dfs -copyToLocal /hosts
[root@hadoop101.yinzhengjie.org.cn ~]# 
[root@hadoop101.yinzhengjie.org.cn ~]# ll
total 4
-rw-r--r-- 1 root root 433 Mar 16 10:57 hosts
[root@hadoop101.yinzhengjie.org.cn ~]# 
[root@hadoop101.yinzhengjie.org.cn ~]# cat hosts 
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6

#Hadoop cluster
172.200.4.101 hadoop101.yinzhengjie.org.cn
172.200.4.102 hadoop102.yinzhengjie.org.cn
172.200.4.103 hadoop103.yinzhengjie.org.cn
172.200.4.104 hadoop104.yinzhengjie.org.cn
172.200.4.105 hadoop105.yinzhengjie.org.cn
172.200.4.106 hadoop106.yinzhengjie.org.cn
[root@hadoop101.yinzhengjie.org.cn ~]# 
[root@hadoop101.yinzhengjie.org.cn ~]# 
[root@hadoop101.yinzhengjie.org.cn ~]# hdfs dfs -text /hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6

#Hadoop cluster
172.200.4.101 hadoop101.yinzhengjie.org.cn
172.200.4.102 hadoop102.yinzhengjie.org.cn
172.200.4.103 hadoop103.yinzhengjie.org.cn
172.200.4.104 hadoop104.yinzhengjie.org.cn
172.200.4.105 hadoop105.yinzhengjie.org.cn
172.200.4.106 hadoop106.yinzhengjie.org.cn
[root@hadoop101.yinzhengjie.org.cn ~]# 
[root@hadoop101.yinzhengjie.org.cn ~]# hdfs dfs -copyToLocal /hosts         #和get命令功能类似,也是下载文件到本地
[root@hadoop101.yinzhengjie.org.cn ~]# ll
total 0
[root@hadoop101.yinzhengjie.org.cn ~]# 
[root@hadoop101.yinzhengjie.org.cn ~]# hdfs dfs -ls /
Found 5 items
-rw-r--r--   3 root supergroup          86 2020-03-16 11:15 /host.log
-rw-r--r--   2 root supergroup         519 2020-03-16 11:09 /hosts
drwxrwx---   - root supergroup           0 2020-03-12 19:20 /tmp
drwxrwx---   - root yinzhengjie          0 2020-03-12 16:51 /yinzhengjie2020
drwxr-xr-x   - root supergroup           0 2020-03-16 10:28 /yum.repos.d
[root@hadoop101.yinzhengjie.org.cn ~]# 
[root@hadoop101.yinzhengjie.org.cn ~]# hdfs dfs -text /host.log
172.200.4.107 hadoop107.yinzhengjie.org.cn
172.200.4.108 hadoop108.yinzhengjie.org.cn
[root@hadoop101.yinzhengjie.org.cn ~]# 
[root@hadoop101.yinzhengjie.org.cn ~]# 
[root@hadoop101.yinzhengjie.org.cn ~]# hdfs dfs -text /hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6

#Hadoop cluster
172.200.4.101 hadoop101.yinzhengjie.org.cn
172.200.4.102 hadoop102.yinzhengjie.org.cn
172.200.4.103 hadoop103.yinzhengjie.org.cn
172.200.4.104 hadoop104.yinzhengjie.org.cn
172.200.4.105 hadoop105.yinzhengjie.org.cn
172.200.4.106 hadoop106.yinzhengjie.org.cn
172.200.4.107 hadoop107.yinzhengjie.org.cn
172.200.4.108 hadoop108.yinzhengjie.org.cn
[root@hadoop101.yinzhengjie.org.cn ~]# 
[root@hadoop101.yinzhengjie.org.cn ~]# hdfs dfs -getmerge /host.log /hosts merge.log
[root@hadoop101.yinzhengjie.org.cn ~]# 
[root@hadoop101.yinzhengjie.org.cn ~]# ll
total 4
-rw-r--r-- 1 root root 605 Mar 16 11:21 merge.log
[root@hadoop101.yinzhengjie.org.cn ~]# 
[root@hadoop101.yinzhengjie.org.cn ~]# cat merge.log 
172.200.4.107 hadoop107.yinzhengjie.org.cn
172.200.4.108 hadoop108.yinzhengjie.org.cn
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6

#Hadoop cluster
172.200.4.101 hadoop101.yinzhengjie.org.cn
172.200.4.102 hadoop102.yinzhengjie.org.cn
172.200.4.103 hadoop103.yinzhengjie.org.cn
172.200.4.104 hadoop104.yinzhengjie.org.cn
172.200.4.105 hadoop105.yinzhengjie.org.cn
172.200.4.106 hadoop106.yinzhengjie.org.cn
172.200.4.107 hadoop107.yinzhengjie.org.cn
172.200.4.108 hadoop108.yinzhengjie.org.cn
[root@hadoop101.yinzhengjie.org.cn ~]# 
[root@hadoop101.yinzhengjie.org.cn ~]# 
[root@hadoop101.yinzhengjie.org.cn ~]# hdfs dfs -getmerge /host.log /hosts merge.log      #将HDFS的集群的根目录下host.log文件和hosts文件的内容下载合并到本地的merge.log文件中

16>.将本地文件或目录上传到HDFS集群

[root@hadoop101.yinzhengjie.org.cn ~]# hdfs dfs  -ls /
Found 4 items
drwxr-xr-x   - root supergroup          0 2020-03-12 19:20 /inputDir
drwxr-xr-x   - root supergroup          0 2020-03-12 19:20 /outputDir
drwxrwx---   - root supergroup          0 2020-03-12 19:20 /tmp
drwxrwx---   - root supergroup          0 2020-03-12 16:51 /yinzhengjie
[root@hadoop101.yinzhengjie.org.cn ~]# 
[root@hadoop101.yinzhengjie.org.cn ~]# 
[root@hadoop101.yinzhengjie.org.cn ~]# cat /etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6

#Hadoop cluster
172.200.4.101 hadoop101.yinzhengjie.org.cn
172.200.4.102 hadoop102.yinzhengjie.org.cn
172.200.4.103 hadoop103.yinzhengjie.org.cn
172.200.4.104 hadoop104.yinzhengjie.org.cn
172.200.4.105 hadoop105.yinzhengjie.org.cn
172.200.4.106 hadoop106.yinzhengjie.org.cn
[root@hadoop101.yinzhengjie.org.cn ~]# 
[root@hadoop101.yinzhengjie.org.cn ~]# hdfs dfs -put /etc/hosts /
[root@hadoop101.yinzhengjie.org.cn ~]# 
[root@hadoop101.yinzhengjie.org.cn ~]# hdfs dfs  -ls /
Found 5 items
-rw-r--r--   3 root supergroup        433 2020-03-16 09:14 /hosts
drwxr-xr-x   - root supergroup          0 2020-03-12 19:20 /inputDir
drwxr-xr-x   - root supergroup          0 2020-03-12 19:20 /outputDir
drwxrwx---   - root supergroup          0 2020-03-12 19:20 /tmp
drwxrwx---   - root supergroup          0 2020-03-12 16:51 /yinzhengjie
[root@hadoop101.yinzhengjie.org.cn ~]# 
[root@hadoop101.yinzhengjie.org.cn ~]# 
[root@hadoop101.yinzhengjie.org.cn ~]# hdfs dfs -put /etc/hosts /              #将本地的"/etc/hosts"文件上传到hdfs的根路径下
[root@hadoop101.yinzhengjie.org.cn ~]# 
[root@hadoop101.yinzhengjie.org.cn ~]# hdfs dfs  -ls /
Found 5 items
-rw-r--r--   3 root supergroup        433 2020-03-16 09:14 /hosts
drwxr-xr-x   - root supergroup          0 2020-03-12 19:20 /inputDir
drwxr-xr-x   - root supergroup          0 2020-03-12 19:20 /outputDir
drwxrwx---   - root supergroup          0 2020-03-12 19:20 /tmp
drwxrwx---   - root supergroup          0 2020-03-12 16:51 /yinzhengjie
[root@hadoop101.yinzhengjie.org.cn ~]# 
[root@hadoop101.yinzhengjie.org.cn ~]# ll /etc/yum.repos.d/
total 32
-rw-r--r--. 1 root root 1664 Nov 23  2018 CentOS-Base.repo
-rw-r--r--. 1 root root 1309 Nov 23  2018 CentOS-CR.repo
-rw-r--r--. 1 root root  649 Nov 23  2018 CentOS-Debuginfo.repo
-rw-r--r--. 1 root root  314 Nov 23  2018 CentOS-fasttrack.repo
-rw-r--r--. 1 root root  630 Nov 23  2018 CentOS-Media.repo
-rw-r--r--. 1 root root 1331 Nov 23  2018 CentOS-Sources.repo
-rw-r--r--. 1 root root 5701 Nov 23  2018 CentOS-Vault.repo
[root@hadoop101.yinzhengjie.org.cn ~]# 
[root@hadoop101.yinzhengjie.org.cn ~]# hdfs dfs -put /etc/yum.repos.d/ /
[root@hadoop101.yinzhengjie.org.cn ~]# 
[root@hadoop101.yinzhengjie.org.cn ~]# hdfs dfs  -ls /
Found 6 items
-rw-r--r--   3 root supergroup        433 2020-03-16 09:14 /hosts
drwxr-xr-x   - root supergroup          0 2020-03-12 19:20 /inputDir
drwxr-xr-x   - root supergroup          0 2020-03-12 19:20 /outputDir
drwxrwx---   - root supergroup          0 2020-03-12 19:20 /tmp
drwxrwx---   - root supergroup          0 2020-03-12 16:51 /yinzhengjie
drwxr-xr-x   - root supergroup          0 2020-03-16 09:16 /yum.repos.d
[root@hadoop101.yinzhengjie.org.cn ~]# 
[root@hadoop101.yinzhengjie.org.cn ~]# 
[root@hadoop101.yinzhengjie.org.cn ~]# hdfs dfs  -ls /yum.repos.d
Found 7 items
-rw-r--r--   3 root supergroup       1664 2020-03-16 09:16 /yum.repos.d/CentOS-Base.repo
-rw-r--r--   3 root supergroup       1309 2020-03-16 09:16 /yum.repos.d/CentOS-CR.repo
-rw-r--r--   3 root supergroup        649 2020-03-16 09:16 /yum.repos.d/CentOS-Debuginfo.repo
-rw-r--r--   3 root supergroup        630 2020-03-16 09:16 /yum.repos.d/CentOS-Media.repo
-rw-r--r--   3 root supergroup       1331 2020-03-16 09:16 /yum.repos.d/CentOS-Sources.repo
-rw-r--r--   3 root supergroup       5701 2020-03-16 09:16 /yum.repos.d/CentOS-Vault.repo
-rw-r--r--   3 root supergroup        314 2020-03-16 09:16 /yum.repos.d/CentOS-fasttrack.repo
[root@hadoop101.yinzhengjie.org.cn ~]# 
[root@hadoop101.yinzhengjie.org.cn ~]# 
[root@hadoop101.yinzhengjie.org.cn ~]# hdfs dfs -put /etc/yum.repos.d/ /          #将本地的"/etc/yum.repos.d"目录上传到hdfs的根路径下
[root@hadoop101.yinzhengjie.org.cn ~]# hdfs dfs -ls /
Found 2 items
drwxrwx---   - root supergroup           0 2020-03-12 19:20 /tmp
drwxrwx---   - root yinzhengjie          0 2020-03-12 16:51 /yinzhengjie2020
[root@hadoop101.yinzhengjie.org.cn ~]# 
[root@hadoop101.yinzhengjie.org.cn ~]# hdfs dfs -copyFromLocal /etc/hosts /
[root@hadoop101.yinzhengjie.org.cn ~]# 
[root@hadoop101.yinzhengjie.org.cn ~]# hdfs dfs -ls /
Found 3 items
-rw-r--r--   3 root supergroup         433 2020-03-16 10:27 /hosts
drwxrwx---   - root supergroup           0 2020-03-12 19:20 /tmp
drwxrwx---   - root yinzhengjie          0 2020-03-12 16:51 /yinzhengjie2020
[root@hadoop101.yinzhengjie.org.cn ~]# 
[root@hadoop101.yinzhengjie.org.cn ~]# hdfs dfs -copyFromLocal /etc/hosts /        #和put命令功能类似,也是拷贝本地文件到hdfs集群上
[root@hadoop101.yinzhengjie.org.cn ~]# ll /etc/yum.repos.d/
total 32
-rw-r--r--. 1 root root 1664 Nov 23  2018 CentOS-Base.repo
-rw-r--r--. 1 root root 1309 Nov 23  2018 CentOS-CR.repo
-rw-r--r--. 1 root root  649 Nov 23  2018 CentOS-Debuginfo.repo
-rw-r--r--. 1 root root  314 Nov 23  2018 CentOS-fasttrack.repo
-rw-r--r--. 1 root root  630 Nov 23  2018 CentOS-Media.repo
-rw-r--r--. 1 root root 1331 Nov 23  2018 CentOS-Sources.repo
-rw-r--r--. 1 root root 5701 Nov 23  2018 CentOS-Vault.repo
[root@hadoop101.yinzhengjie.org.cn ~]# 
[root@hadoop101.yinzhengjie.org.cn ~]# hdfs dfs -copyFromLocal /etc/yum.repos.d /
[root@hadoop101.yinzhengjie.org.cn ~]# 
[root@hadoop101.yinzhengjie.org.cn ~]# hdfs dfs -ls /
Found 4 items
-rw-r--r--   3 root supergroup         433 2020-03-16 10:27 /hosts
drwxrwx---   - root supergroup           0 2020-03-12 19:20 /tmp
drwxrwx---   - root yinzhengjie          0 2020-03-12 16:51 /yinzhengjie2020
drwxr-xr-x   - root supergroup           0 2020-03-16 10:28 /yum.repos.d
[root@hadoop101.yinzhengjie.org.cn ~]# 
[root@hadoop101.yinzhengjie.org.cn ~]# hdfs dfs -ls /yum.repos.d
Found 7 items
-rw-r--r--   3 root supergroup       1664 2020-03-16 10:28 /yum.repos.d/CentOS-Base.repo
-rw-r--r--   3 root supergroup       1309 2020-03-16 10:28 /yum.repos.d/CentOS-CR.repo
-rw-r--r--   3 root supergroup        649 2020-03-16 10:28 /yum.repos.d/CentOS-Debuginfo.repo
-rw-r--r--   3 root supergroup        630 2020-03-16 10:28 /yum.repos.d/CentOS-Media.repo
-rw-r--r--   3 root supergroup       1331 2020-03-16 10:28 /yum.repos.d/CentOS-Sources.repo
-rw-r--r--   3 root supergroup       5701 2020-03-16 10:28 /yum.repos.d/CentOS-Vault.repo
-rw-r--r--   3 root supergroup        314 2020-03-16 10:28 /yum.repos.d/CentOS-fasttrack.repo
[root@hadoop101.yinzhengjie.org.cn ~]# 
[root@hadoop101.yinzhengjie.org.cn ~]# hdfs dfs -copyFromLocal /etc/yum.repos.d /     #拷贝本地目录到hdfs集群上,保留源文件,优点类似于windows的复制操作
[root@hadoop101.yinzhengjie.org.cn ~]# hdfs dfs -ls /
Found 4 items
-rw-r--r--   2 root supergroup         519 2020-03-16 11:09 /hosts
drwxrwx---   - root supergroup           0 2020-03-12 19:20 /tmp
drwxrwx---   - root yinzhengjie          0 2020-03-12 16:51 /yinzhengjie2020
drwxr-xr-x   - root supergroup           0 2020-03-16 10:28 /yum.repos.d
[root@hadoop101.yinzhengjie.org.cn ~]# 
[root@hadoop101.yinzhengjie.org.cn ~]# ll
total 4
-rw-r--r-- 1 root root 86 Mar 16 11:08 host.log
[root@hadoop101.yinzhengjie.org.cn ~]# 
[root@hadoop101.yinzhengjie.org.cn ~]# hdfs dfs -moveFromLocal host.log /
[root@hadoop101.yinzhengjie.org.cn ~]# 
[root@hadoop101.yinzhengjie.org.cn ~]# ll
total 0
[root@hadoop101.yinzhengjie.org.cn ~]# 
[root@hadoop101.yinzhengjie.org.cn ~]# hdfs dfs -ls /
Found 5 items
-rw-r--r--   3 root supergroup          86 2020-03-16 11:15 /host.log
-rw-r--r--   2 root supergroup         519 2020-03-16 11:09 /hosts
drwxrwx---   - root supergroup           0 2020-03-12 19:20 /tmp
drwxrwx---   - root yinzhengjie          0 2020-03-12 16:51 /yinzhengjie2020
drwxr-xr-x   - root supergroup           0 2020-03-16 10:28 /yum.repos.d
[root@hadoop101.yinzhengjie.org.cn ~]# 
[root@hadoop101.yinzhengjie.org.cn ~]# 
[root@hadoop101.yinzhengjie.org.cn ~]# hdfs dfs -moveFromLocal host.log /          #将本地文件拷贝到hdfs集群上,但源文件并不保留,有点类似于windows的剪切操作

17>.将本地文件内容追加到hdfs集群中已经存在的文件

[root@hadoop101.yinzhengjie.org.cn ~]# hdfs dfs -text /hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6

#Hadoop cluster
172.200.4.101 hadoop101.yinzhengjie.org.cn
172.200.4.102 hadoop102.yinzhengjie.org.cn
172.200.4.103 hadoop103.yinzhengjie.org.cn
172.200.4.104 hadoop104.yinzhengjie.org.cn
172.200.4.105 hadoop105.yinzhengjie.org.cn
172.200.4.106 hadoop106.yinzhengjie.org.cn
[root@hadoop101.yinzhengjie.org.cn ~]# 
[root@hadoop101.yinzhengjie.org.cn ~]# ll
total 4
-rw-r--r-- 1 root root 86 Mar 16 11:08 host.log
[root@hadoop101.yinzhengjie.org.cn ~]# 
[root@hadoop101.yinzhengjie.org.cn ~]# cat host.log 
172.200.4.107 hadoop107.yinzhengjie.org.cn
172.200.4.108 hadoop108.yinzhengjie.org.cn
[root@hadoop101.yinzhengjie.org.cn ~]# 
[root@hadoop101.yinzhengjie.org.cn ~]# hdfs dfs -appendToFile host.log /hosts
[root@hadoop101.yinzhengjie.org.cn ~]# 
[root@hadoop101.yinzhengjie.org.cn ~]# ll
total 4
-rw-r--r-- 1 root root 86 Mar 16 11:08 host.log
[root@hadoop101.yinzhengjie.org.cn ~]# 
[root@hadoop101.yinzhengjie.org.cn ~]# hdfs dfs -text /hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6

#Hadoop cluster
172.200.4.101 hadoop101.yinzhengjie.org.cn
172.200.4.102 hadoop102.yinzhengjie.org.cn
172.200.4.103 hadoop103.yinzhengjie.org.cn
172.200.4.104 hadoop104.yinzhengjie.org.cn
172.200.4.105 hadoop105.yinzhengjie.org.cn
172.200.4.106 hadoop106.yinzhengjie.org.cn
172.200.4.107 hadoop107.yinzhengjie.org.cn
172.200.4.108 hadoop108.yinzhengjie.org.cn
[root@hadoop101.yinzhengjie.org.cn ~]# 
[root@hadoop101.yinzhengjie.org.cn ~]# 
[root@hadoop101.yinzhengjie.org.cn ~]# hdfs dfs -appendToFile host.log /hosts      #将本地的"host.log"文件内容追加到HDFS集群根目录下的hosts文件中

18>.显示一个文件的末尾

[root@hadoop101.yinzhengjie.org.cn ~]# hdfs dfs -tail  /hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6

#Hadoop cluster
172.200.4.101 hadoop101.yinzhengjie.org.cn
172.200.4.102 hadoop102.yinzhengjie.org.cn
172.200.4.103 hadoop103.yinzhengjie.org.cn
172.200.4.104 hadoop104.yinzhengjie.org.cn
172.200.4.105 hadoop105.yinzhengjie.org.cn
172.200.4.106 hadoop106.yinzhengjie.org.cn
172.200.4.107 hadoop107.yinzhengjie.org.cn
172.200.4.108 hadoop108.yinzhengjie.org.cn
[root@hadoop101.yinzhengjie.org.cn ~]# 
[root@hadoop101.yinzhengjie.org.cn ~]# hdfs dfs -tail /hosts                #查看文件内容
[root@hadoop101.yinzhengjie.org.cn ~]# hdfs dfs -tail -f /hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6

#Hadoop cluster
172.200.4.101 hadoop101.yinzhengjie.org.cn
172.200.4.102 hadoop102.yinzhengjie.org.cn
172.200.4.103 hadoop103.yinzhengjie.org.cn
172.200.4.104 hadoop104.yinzhengjie.org.cn
172.200.4.105 hadoop105.yinzhengjie.org.cn
172.200.4.106 hadoop106.yinzhengjie.org.cn
172.200.4.107 hadoop107.yinzhengjie.org.cn
172.200.4.108 hadoop108.yinzhengjie.org.cn
[root@hadoop101.yinzhengjie.org.cn ~]# hdfs dfs -tail -f /hosts              #查看文件内容并实时监控文件末尾是否有内容追加进来

19>.查找文件或目录

[root@hadoop101.yinzhengjie.com ~]# hdfs dfs -ls /
Found 4 items
drwxrwxrwx   - root admingroup          0 2020-10-22 19:38 /input
drwxr-xr-x   - root admingroup          0 2020-11-09 06:23 /output
drwxrwxrwx   - root admingroup          0 2020-10-22 20:03 /user
drwxrwxrwx   - root admingroup          0 2020-11-09 03:41 /yinzhengjie
[root@hadoop101.yinzhengjie.com ~]# 
[root@hadoop101.yinzhengjie.com ~]# hdfs dfs -mkdir /LOGS
[root@hadoop101.yinzhengjie.com ~]# 
[root@hadoop101.yinzhengjie.com ~]# hdfs dfs -ls /
Found 5 items
drwxr-xr-x   - root admingroup          0 2020-11-09 07:21 /LOGS
drwxrwxrwx   - root admingroup          0 2020-10-22 19:38 /input
drwxr-xr-x   - root admingroup          0 2020-11-09 06:23 /output
drwxrwxrwx   - root admingroup          0 2020-10-22 20:03 /user
drwxrwxrwx   - root admingroup          0 2020-11-09 03:41 /yinzhengjie
[root@hadoop101.yinzhengjie.com ~]# 
[root@hadoop101.yinzhengjie.com ~]# 
[root@hadoop101.yinzhengjie.com ~]# hdfs dfs -find / -name LOGS -print
/LOGS
[root@hadoop101.yinzhengjie.com ~]# 
[root@hadoop101.yinzhengjie.com ~]# 
[root@hadoop101.yinzhengjie.com ~]# hdfs dfs -find / -name LOGS -print
[root@hadoop101.yinzhengjie.com ~]# hdfs dfs -find / -name LOGS -print
/LOGS
[root@hadoop101.yinzhengjie.com ~]# 
[root@hadoop101.yinzhengjie.com ~]# hdfs dfs -find / -iname LOGS -print
/LOGS
/user/root/.Trash/Current/yinzhengjie/logs
/user/root/.Trash/Current/yinzhengjie/logs/nodemanager/aggregation/root/logs
/yinzhengjie/logs
[root@hadoop101.yinzhengjie.com ~]# 
[root@hadoop101.yinzhengjie.com ~]# 
[root@hadoop101.yinzhengjie.com ~]# hdfs dfs -find / -iname LOGS -print

20.查看命令的帮助信息

[root@hadoop101.yinzhengjie.org.cn ~]# hdfs dfs -help rm
-rm [-f] [-r|-R] [-skipTrash] [-safely] <src> ... :
  Delete all files that match the specified file pattern. Equivalent to the Unix
  command "rm <src>"
                                                                                 
  -f          If the file does not exist, do not display a diagnostic message or 
              modify the exit status to reflect an error.                        
  -[rR]       Recursively deletes directories.                                   
  -skipTrash  option bypasses trash, if enabled, and immediately deletes <src>.  
  -safely     option requires safety confirmation, if enabled, requires          
              confirmation before deleting large directory with more than        
              <hadoop.shell.delete.limit.num.files> files. Delay is expected when
              walking over large directory recursively to count the number of    
              files to be deleted before the confirmation.                       
[root@hadoop101.yinzhengjie.org.cn ~]# 
[root@hadoop101.yinzhengjie.org.cn ~]# 
[root@hadoop101.yinzhengjie.org.cn ~]# hdfs dfs -help rm
[root@hadoop101.yinzhengjie.com ~]# hdfs dfs -usage rm
Usage: hadoop fs [generic options] -rm [-f] [-r|-R] [-skipTrash] [-safely] <src> ...
[root@hadoop101.yinzhengjie.com ~]# 
[root@hadoop101.yinzhengjie.com ~]# hdfs dfs -usage rm
[root@hadoop101.yinzhengjie.org.cn ~]# hdfs dfs -help mkdir
-mkdir [-p] <path> ... :
  Create a directory in specified location.
                                                  
  -p  Do not fail if the directory already exists 
[root@hadoop101.yinzhengjie.org.cn ~]# 
[root@hadoop101.yinzhengjie.org.cn ~]# 
[root@hadoop101.yinzhengjie.org.cn ~]# hdfs dfs -help mkdir
[root@hadoop101.yinzhengjie.com ~]# hdfs dfs -usage mkdir
Usage: hadoop fs [generic options] -mkdir [-p] <path> ...
[root@hadoop101.yinzhengjie.com ~]# 
[root@hadoop101.yinzhengjie.com ~]# hdfs dfs -usage mkdir
[root@hadoop101.yinzhengjie.org.cn ~]# hdfs dfs -help cp
-cp [-f] [-p | -p[topax]] [-d] <src> ... <dst> :
  Copy files that match the file pattern <src> to a destination.  When copying
  multiple files, the destination must be a directory. Passing -p preserves status
  [topax] (timestamps, ownership, permission, ACLs, XAttr). If -p is specified
  with no <arg>, then preserves timestamps, ownership, permission. If -pa is
  specified, then preserves permission also because ACL is a super-set of
  permission. Passing -f overwrites the destination if it already exists. raw
  namespace extended attributes are preserved if (1) they are supported (HDFS
  only) and, (2) all of the source and target pathnames are in the /.reserved/raw
  hierarchy. raw namespace xattr preservation is determined solely by the presence
  (or absence) of the /.reserved/raw prefix and not by the -p option. Passing -d
  will skip creation of temporary file(<dst>._COPYING_).
[root@hadoop101.yinzhengjie.org.cn ~]# 
[root@hadoop101.yinzhengjie.org.cn ~]# hdfs dfs -help cp
[root@hadoop101.yinzhengjie.com ~]# hdfs dfs -usage cp
Usage: hadoop fs [generic options] -cp [-f] [-p | -p[topax]] [-d] <src> ... <dst>
[root@hadoop101.yinzhengjie.com ~]# 
[root@hadoop101.yinzhengjie.com ~]# hdfs dfs -usage cp
[root@hadoop101.yinzhengjie.org.cn ~]# hdfs dfs -help setrep
-setrep [-R] [-w] <rep> <path> ... :
  Set the replication level of a file. If <path> is a directory then the command
  recursively changes the replication factor of all files under the directory tree
  rooted at <path>.
                                                                                 
  -w  It requests that the command waits for the replication to complete. This   
      can potentially take a very long time.                                     
  -R  It is accepted for backwards compatibility. It has no effect.              
[root@hadoop101.yinzhengjie.org.cn ~]# 
[root@hadoop101.yinzhengjie.org.cn ~]# 
[root@hadoop101.yinzhengjie.org.cn ~]# hdfs dfs -help setrep
[root@hadoop101.yinzhengjie.com ~]# hdfs dfs -usage setrep
Usage: hadoop fs [generic options] -setrep [-R] [-w] <rep> <path> ...
[root@hadoop101.yinzhengjie.com ~]# 
[root@hadoop101.yinzhengjie.com ~]# hdfs dfs -usage setrep
[root@hadoop101.yinzhengjie.org.cn ~]# hdfs dfs -help getmerge
-getmerge [-nl] [-skip-empty-file] <src> <localdst> :
  Get all the files in the directories that match the source file pattern and
  merge and sort them to only one file on local fs. <src> is kept.
                                                                     
  -nl               Add a newline character at the end of each file. 
  -skip-empty-file  Do not add new line character for empty file.    
[root@hadoop101.yinzhengjie.org.cn ~]# 
[root@hadoop101.yinzhengjie.org.cn ~]# hdfs dfs -help getmerge
[root@hadoop101.yinzhengjie.com ~]# hdfs dfs -usage getmerge
Usage: hadoop fs [generic options] -getmerge [-nl] [-skip-empty-file] <src> <localdst>
[root@hadoop101.yinzhengjie.com ~]# 
[root@hadoop101.yinzhengjie.com ~]# hdfs dfs -usage getmerge
[root@hadoop101.yinzhengjie.com ~]# hdfs dfs -help find
-find <path> ... <expression> ... :
  Finds all files that match the specified expression and
  applies selected actions to them. If no <path> is specified
  then defaults to the current working directory. If no
  expression is specified then defaults to -print.
  
  The following primary expressions are recognised:
    -name pattern
    -iname pattern
      Evaluates as true if the basename of the file matches the
      pattern using standard file system globbing.
      If -iname is used then the match is case insensitive.
  
    -print
    -print0
      Always evaluates to true. Causes the current pathname to be
      written to standard output followed by a newline. If the -print0
      expression is used then an ASCII NULL character is appended rather
      than a newline.
  
  The following operators are recognised:
    expression -a expression
    expression -and expression
    expression expression
      Logical AND operator for joining two expressions. Returns
      true if both child expressions return true. Implied by the
      juxtaposition of two expressions and so does not need to be
      explicitly specified. The second expression will not be
      applied if the first fails.
[root@hadoop101.yinzhengjie.com ~]# 
[root@hadoop101.yinzhengjie.com ~]# hdfs dfs -help find
[root@hadoop101.yinzhengjie.com ~]# hdfs dfs -usage find
Usage: hadoop fs [generic options] -find <path> ... <expression> ...
[root@hadoop101.yinzhengjie.com ~]# 
[root@hadoop101.yinzhengjie.com ~]# hdfs dfs -usage find

 

二.NameNode的镜像文件和编辑日志管理相关命令

1>.下载镜像文件

[root@hadoop101.yinzhengjie.org.cn ~]# ll /yinzhengjie/softwares/hadoop-2.10.0/data/tmp/dfs/name/current/
total 10396
-rw-r--r-- 1 root root      42 Mar 12 03:27 edits_0000000000000000001-0000000000000000002
-rw-r--r-- 1 root root      42 Mar 12 03:27 edits_0000000000000000003-0000000000000000004
-rw-r--r-- 1 root root 1048576 Mar 12 03:27 edits_0000000000000000005-0000000000000000005
-rw-r--r-- 1 root root 1048576 Mar 12 03:27 edits_0000000000000000006-0000000000000000006
-rw-r--r-- 1 root root      42 Mar 12 03:29 edits_0000000000000000007-0000000000000000008
-rw-r--r-- 1 root root 1048576 Mar 12 03:29 edits_0000000000000000009-0000000000000000009
-rw-r--r-- 1 root root      42 Mar 12 03:32 edits_0000000000000000010-0000000000000000011
-rw-r--r-- 1 root root      42 Mar 12 04:32 edits_0000000000000000012-0000000000000000013
-rw-r--r-- 1 root root 1048576 Mar 12 04:32 edits_0000000000000000014-0000000000000000014
-rw-r--r-- 1 root root      42 Mar 12 04:57 edits_0000000000000000015-0000000000000000016
-rw-r--r-- 1 root root 1048576 Mar 12 04:57 edits_0000000000000000017-0000000000000000017
-rw-r--r-- 1 root root      42 Mar 12 05:03 edits_0000000000000000018-0000000000000000019
-rw-r--r-- 1 root root 1048576 Mar 12 05:03 edits_0000000000000000020-0000000000000000020
-rw-r--r-- 1 root root      42 Mar 12 07:46 edits_0000000000000000021-0000000000000000022
-rw-r--r-- 1 root root 1048576 Mar 12 07:46 edits_0000000000000000023-0000000000000000023
-rw-r--r-- 1 root root      42 Mar 12 08:41 edits_0000000000000000024-0000000000000000025
-rw-r--r-- 1 root root      42 Mar 12 09:41 edits_0000000000000000026-0000000000000000027
-rw-r--r-- 1 root root      42 Mar 12 10:41 edits_0000000000000000028-0000000000000000029
-rw-r--r-- 1 root root      42 Mar 12 11:41 edits_0000000000000000030-0000000000000000031
-rw-r--r-- 1 root root      42 Mar 12 12:41 edits_0000000000000000032-0000000000000000033
-rw-r--r-- 1 root root      42 Mar 12 13:41 edits_0000000000000000034-0000000000000000035
-rw-r--r-- 1 root root      42 Mar 12 14:41 edits_0000000000000000036-0000000000000000037
-rw-r--r-- 1 root root     672 Mar 12 15:41 edits_0000000000000000038-0000000000000000046
-rw-r--r-- 1 root root 1048576 Mar 12 15:41 edits_0000000000000000047-0000000000000000047
-rw-r--r-- 1 root root      42 Mar 12 15:54 edits_0000000000000000048-0000000000000000049
-rw-r--r-- 1 root root   23130 Mar 12 16:54 edits_0000000000000000050-0000000000000000237
-rw-r--r-- 1 root root    1140 Mar 12 17:54 edits_0000000000000000238-0000000000000000246
-rw-r--r-- 1 root root      42 Mar 12 18:54 edits_0000000000000000247-0000000000000000248
-rw-r--r-- 1 root root   24270 Mar 12 19:54 edits_0000000000000000249-0000000000000000448
-rw-r--r-- 1 root root 1048576 Mar 12 19:54 edits_0000000000000000449-0000000000000000449
-rw-r--r-- 1 root root      42 Mar 17 15:07 edits_0000000000000000450-0000000000000000451
-rw-r--r-- 1 root root      42 Mar 17 16:07 edits_0000000000000000452-0000000000000000453
-rw-r--r-- 1 root root 1048576 Mar 17 16:07 edits_inprogress_0000000000000000454
-rw-r--r-- 1 root root    3595 Mar 17 14:08 fsimage_0000000000000000449
-rw-r--r-- 1 root root      62 Mar 17 14:08 fsimage_0000000000000000449.md5
-rw-r--r-- 1 root root    3595 Mar 17 16:07 fsimage_0000000000000000453
-rw-r--r-- 1 root root      62 Mar 17 16:07 fsimage_0000000000000000453.md5
-rw-r--r-- 1 root root       4 Mar 17 16:07 seen_txid
-rw-r--r-- 1 root root     217 Mar 17 14:08 VERSION
[root@hadoop101.yinzhengjie.org.cn ~]# 
[root@hadoop101.yinzhengjie.org.cn ~]# ll
total 0
[root@hadoop101.yinzhengjie.org.cn ~]# 
[root@hadoop101.yinzhengjie.org.cn ~]# hdfs oiv -p XML -i /yinzhengjie/softwares/hadoop-2.10.0/data/tmp/dfs/name/current/fsimage_0000000000000000453 -o ./fsimage.xml
20/03/17 16:47:56 INFO offlineImageViewer.FSImageHandler: Loading 3 strings
[root@hadoop101.yinzhengjie.org.cn ~]# 
[root@hadoop101.yinzhengjie.org.cn ~]# ll
total 16
-rw-r--r-- 1 root root 13956 Mar 17 16:47 fsimage.xml
[root@hadoop101.yinzhengjie.org.cn ~]# 
[root@hadoop101.yinzhengjie.org.cn ~]# 
[root@hadoop101.yinzhengjie.org.cn ~]# hdfs oiv -p XML -i /yinzhengjie/softwares/hadoop-2.10.0/data/tmp/dfs/name/current/fsimage_0000000000000000453 -o ./fsimage.xml

2>.下载编辑日志

[root@hadoop101.yinzhengjie.org.cn ~]# ll /yinzhengjie/softwares/hadoop-2.10.0/data/tmp/dfs/name/current/
total 10396
-rw-r--r-- 1 root root      42 Mar 12 03:27 edits_0000000000000000001-0000000000000000002
-rw-r--r-- 1 root root      42 Mar 12 03:27 edits_0000000000000000003-0000000000000000004
-rw-r--r-- 1 root root 1048576 Mar 12 03:27 edits_0000000000000000005-0000000000000000005
-rw-r--r-- 1 root root 1048576 Mar 12 03:27 edits_0000000000000000006-0000000000000000006
-rw-r--r-- 1 root root      42 Mar 12 03:29 edits_0000000000000000007-0000000000000000008
-rw-r--r-- 1 root root 1048576 Mar 12 03:29 edits_0000000000000000009-0000000000000000009
-rw-r--r-- 1 root root      42 Mar 12 03:32 edits_0000000000000000010-0000000000000000011
-rw-r--r-- 1 root root      42 Mar 12 04:32 edits_0000000000000000012-0000000000000000013
-rw-r--r-- 1 root root 1048576 Mar 12 04:32 edits_0000000000000000014-0000000000000000014
-rw-r--r-- 1 root root      42 Mar 12 04:57 edits_0000000000000000015-0000000000000000016
-rw-r--r-- 1 root root 1048576 Mar 12 04:57 edits_0000000000000000017-0000000000000000017
-rw-r--r-- 1 root root      42 Mar 12 05:03 edits_0000000000000000018-0000000000000000019
-rw-r--r-- 1 root root 1048576 Mar 12 05:03 edits_0000000000000000020-0000000000000000020
-rw-r--r-- 1 root root      42 Mar 12 07:46 edits_0000000000000000021-0000000000000000022
-rw-r--r-- 1 root root 1048576 Mar 12 07:46 edits_0000000000000000023-0000000000000000023
-rw-r--r-- 1 root root      42 Mar 12 08:41 edits_0000000000000000024-0000000000000000025
-rw-r--r-- 1 root root      42 Mar 12 09:41 edits_0000000000000000026-0000000000000000027
-rw-r--r-- 1 root root      42 Mar 12 10:41 edits_0000000000000000028-0000000000000000029
-rw-r--r-- 1 root root      42 Mar 12 11:41 edits_0000000000000000030-0000000000000000031
-rw-r--r-- 1 root root      42 Mar 12 12:41 edits_0000000000000000032-0000000000000000033
-rw-r--r-- 1 root root      42 Mar 12 13:41 edits_0000000000000000034-0000000000000000035
-rw-r--r-- 1 root root      42 Mar 12 14:41 edits_0000000000000000036-0000000000000000037
-rw-r--r-- 1 root root     672 Mar 12 15:41 edits_0000000000000000038-0000000000000000046
-rw-r--r-- 1 root root 1048576 Mar 12 15:41 edits_0000000000000000047-0000000000000000047
-rw-r--r-- 1 root root      42 Mar 12 15:54 edits_0000000000000000048-0000000000000000049
-rw-r--r-- 1 root root   23130 Mar 12 16:54 edits_0000000000000000050-0000000000000000237
-rw-r--r-- 1 root root    1140 Mar 12 17:54 edits_0000000000000000238-0000000000000000246
-rw-r--r-- 1 root root      42 Mar 12 18:54 edits_0000000000000000247-0000000000000000248
-rw-r--r-- 1 root root   24270 Mar 12 19:54 edits_0000000000000000249-0000000000000000448
-rw-r--r-- 1 root root 1048576 Mar 12 19:54 edits_0000000000000000449-0000000000000000449
-rw-r--r-- 1 root root      42 Mar 17 15:07 edits_0000000000000000450-0000000000000000451
-rw-r--r-- 1 root root      42 Mar 17 16:07 edits_0000000000000000452-0000000000000000453
-rw-r--r-- 1 root root 1048576 Mar 17 16:07 edits_inprogress_0000000000000000454
-rw-r--r-- 1 root root    3595 Mar 17 14:08 fsimage_0000000000000000449
-rw-r--r-- 1 root root      62 Mar 17 14:08 fsimage_0000000000000000449.md5
-rw-r--r-- 1 root root    3595 Mar 17 16:07 fsimage_0000000000000000453
-rw-r--r-- 1 root root      62 Mar 17 16:07 fsimage_0000000000000000453.md5
-rw-r--r-- 1 root root       4 Mar 17 16:07 seen_txid
-rw-r--r-- 1 root root     217 Mar 17 14:08 VERSION
[root@hadoop101.yinzhengjie.org.cn ~]# 
[root@hadoop101.yinzhengjie.org.cn ~]# ll
total 16
-rw-r--r-- 1 root root 13956 Mar 17 16:47 fsimage.xml
[root@hadoop101.yinzhengjie.org.cn ~]# 
[root@hadoop101.yinzhengjie.org.cn ~]# hdfs oev -p XML -i /yinzhengjie/softwares/hadoop-2.10.0/data/tmp/dfs/name/current/edits_inprogress_0000000000000000454 -o ./edits.xml
[root@hadoop101.yinzhengjie.org.cn ~]# 
[root@hadoop101.yinzhengjie.org.cn ~]# ll
total 20
-rw-r--r-- 1 root root   204 Mar 17 16:54 edits.xml
-rw-r--r-- 1 root root 13956 Mar 17 16:47 fsimage.xml
[root@hadoop101.yinzhengjie.org.cn ~]# 
[root@hadoop101.yinzhengjie.org.cn ~]# hdfs oev -p XML -i /yinzhengjie/softwares/hadoop-2.10.0/data/tmp/dfs/name/current/edits_inprogress_0000000000000000454 -o ./edits.xml

3>.

 

 

三.其它常用命令

1>.集群键数据拷贝

  比如将"hdfs://hadoop101.yinzhengjie.org.cn:9000/yinzhengjie/hosts"的文件拷贝到另一个HDFS集群"hdfs://hadoop110.yinzhengjie.org.cn:9000/yinzhengjie2020/hosts"
    [root@hadoop101.yinzhengjie.org.cn ~]# hadoop distcp hdfs://hadoop101.yinzhengjie.org.cn:9000/yinzhengjie/hosts hdfs://hadoop110.yinzhengjie.org.cn:9000/yinzhengjie2020/hosts      

  博主推荐阅读:
    http://hadoop.apache.org/docs/stable3/hadoop-distcp/DistCp.html

2>.归档小文件

  HDFS存储小文件的弊端分析:
    每个文件均按块存储,每个块的元数据存储在NameNode的内存中,因此HDFS存储小文件会非常低效率。因为大量小文件会耗尽NameNode中的大部分内存。但注意,存储小文件所需要的磁盘容量和数据块的大小无关。
    例如,一个1MB的文件设置未128MB的块存储,实际使用的是1MB的磁盘空间,而不是128MB空间哟。

  解决方案:
    HDFS存档文件或HAR文件,是一个更高效的文件存档工具,它将文件存储HDFS块,在减少NameNode内存使用的同时,允许对文件进行透明的访问。
    具体来说,HDFS存档文件对内还是一个一个独立文件,对NameNode而言却是一个整体一,减少了NameNode的内存消耗。
[root@hadoop101.yinzhengjie.org.cn ~]# hdfs dfs -ls /
Found 3 items
drwxrwx---   - root supergroup          0 2020-03-12 19:20 /tmp
drwxrwx---   - root supergroup          0 2020-03-17 23:17 /yinzhengjie
drwxr-xr-x   - root supergroup          0 2020-03-17 23:20 /yum.repos.d
[root@hadoop101.yinzhengjie.org.cn ~]# 
[root@hadoop101.yinzhengjie.org.cn ~]# hdfs dfs -ls /yinzhengjie
Found 1 items
drwxrwx---   - root supergroup          0 2020-03-12 16:51 /yinzhengjie/jobhistory
[root@hadoop101.yinzhengjie.org.cn ~]# 
[root@hadoop101.yinzhengjie.org.cn ~]# hdfs dfs -ls /yum.repos.d
Found 7 items
-rw-r--r--   3 root supergroup       1664 2020-03-17 23:20 /yum.repos.d/CentOS-Base.repo
-rw-r--r--   3 root supergroup       1309 2020-03-17 23:20 /yum.repos.d/CentOS-CR.repo
-rw-r--r--   3 root supergroup        649 2020-03-17 23:20 /yum.repos.d/CentOS-Debuginfo.repo
-rw-r--r--   3 root supergroup        630 2020-03-17 23:20 /yum.repos.d/CentOS-Media.repo
-rw-r--r--   3 root supergroup       1331 2020-03-17 23:20 /yum.repos.d/CentOS-Sources.repo
-rw-r--r--   3 root supergroup       5701 2020-03-17 23:20 /yum.repos.d/CentOS-Vault.repo
-rw-r--r--   3 root supergroup        314 2020-03-17 23:20 /yum.repos.d/CentOS-fasttrack.repo
[root@hadoop101.yinzhengjie.org.cn ~]# 
[root@hadoop101.yinzhengjie.org.cn ~]# hdfs dfs -ls /yinzhengjie
[root@hadoop101.yinzhengjie.org.cn ~]# 
[root@hadoop101.yinzhengjie.org.cn ~]# hadoop archive -archiveName myFile.har -p /yum.repos.d /yinzhengjie 
20/03/17 23:21:33 INFO client.RMProxy: Connecting to ResourceManager at hadoop106.yinzhengjie.org.cn/172.200.4.106:8032
20/03/17 23:21:34 INFO client.RMProxy: Connecting to ResourceManager at hadoop106.yinzhengjie.org.cn/172.200.4.106:8032
20/03/17 23:21:34 INFO client.RMProxy: Connecting to ResourceManager at hadoop106.yinzhengjie.org.cn/172.200.4.106:8032
20/03/17 23:21:34 INFO mapreduce.JobSubmitter: number of splits:1
20/03/17 23:21:34 INFO Configuration.deprecation: yarn.resourcemanager.system-metrics-publisher.enabled is deprecated. Instead, use 
yarn.system-metrics-publisher.enabled20/03/17 23:21:34 INFO mapreduce.JobSubmitter: Submitting tokens for job: job_1584457946785_0002
20/03/17 23:21:34 INFO conf.Configuration: resource-types.xml not found
20/03/17 23:21:34 INFO resource.ResourceUtils: Unable to find 'resource-types.xml'.
20/03/17 23:21:34 INFO resource.ResourceUtils: Adding resource type - name = memory-mb, units = Mi, type = COUNTABLE
20/03/17 23:21:34 INFO resource.ResourceUtils: Adding resource type - name = vcores, units = , type = COUNTABLE
20/03/17 23:21:35 INFO impl.YarnClientImpl: Submitted application application_1584457946785_0002
20/03/17 23:21:35 INFO mapreduce.Job: The url to track the job: http://hadoop106.yinzhengjie.org.cn:8088/proxy/application_158445794
6785_0002/20/03/17 23:21:35 INFO mapreduce.Job: Running job: job_1584457946785_0002
20/03/17 23:21:40 INFO mapreduce.Job: Job job_1584457946785_0002 running in uber mode : false
20/03/17 23:21:40 INFO mapreduce.Job:  map 0% reduce 0%
20/03/17 23:21:48 INFO mapreduce.Job:  map 100% reduce 0%
20/03/17 23:21:52 INFO mapreduce.Job:  map 100% reduce 100%
20/03/17 23:21:52 INFO mapreduce.Job: Job job_1584457946785_0002 completed successfully
20/03/17 23:21:52 INFO mapreduce.Job: Counters: 49
    File System Counters
        FILE: Number of bytes read=782
        FILE: Number of bytes written=416013
        FILE: Number of read operations=0
        FILE: Number of large read operations=0
        FILE: Number of write operations=0
        HDFS: Number of bytes read=12415
        HDFS: Number of bytes written=12347
        HDFS: Number of read operations=24
        HDFS: Number of large read operations=0
        HDFS: Number of write operations=11
    Job Counters 
        Launched map tasks=1
        Launched reduce tasks=1
        Other local map tasks=1
        Total time spent by all maps in occupied slots (ms)=5851
        Total time spent by all reduces in occupied slots (ms)=2067
        Total time spent by all map tasks (ms)=5851
        Total time spent by all reduce tasks (ms)=2067
        Total vcore-milliseconds taken by all map tasks=5851
        Total vcore-milliseconds taken by all reduce tasks=2067
        Total megabyte-milliseconds taken by all map tasks=5991424
        Total megabyte-milliseconds taken by all reduce tasks=2116608
    Map-Reduce Framework
        Map input records=8
        Map output records=8
        Map output bytes=759
        Map output materialized bytes=782
        Input split bytes=116
        Combine input records=0
        Combine output records=0
        Reduce input groups=8
        Reduce shuffle bytes=782
        Reduce input records=8
        Reduce output records=0
        Spilled Records=16
        Shuffled Maps =1
        Failed Shuffles=0
        Merged Map outputs=1
        GC time elapsed (ms)=417
        CPU time spent (ms)=2840
        Physical memory (bytes) snapshot=486158336
        Virtual memory (bytes) snapshot=4331356160
        Total committed heap usage (bytes)=287309824
    Shuffle Errors
        BAD_ID=0
        CONNECTION=0
        IO_ERROR=0
        WRONG_LENGTH=0
        WRONG_MAP=0
        WRONG_REDUCE=0
    File Input Format Counters 
        Bytes Read=701
    File Output Format Counters 
        Bytes Written=0
[root@hadoop101.yinzhengjie.org.cn ~]# 
[root@hadoop101.yinzhengjie.org.cn ~]# hadoop archive -archiveName myFile.har -p /yum.repos.d /yinzhengjie
[root@hadoop101.yinzhengjie.org.cn ~]# hdfs dfs -ls /
Found 3 items
drwxrwx---   - root supergroup          0 2020-03-12 19:20 /tmp
drwxrwx---   - root supergroup          0 2020-03-17 23:21 /yinzhengjie
drwxr-xr-x   - root supergroup          0 2020-03-17 23:20 /yum.repos.d
[root@hadoop101.yinzhengjie.org.cn ~]# 
[root@hadoop101.yinzhengjie.org.cn ~]# hdfs dfs -ls /yinzhengjie/
Found 2 items
drwxrwx---   - root supergroup          0 2020-03-12 16:51 /yinzhengjie/jobhistory
drwxr-xr-x   - root supergroup          0 2020-03-17 23:21 /yinzhengjie/myFile.har
[root@hadoop101.yinzhengjie.org.cn ~]# 
[root@hadoop101.yinzhengjie.org.cn ~]# 
[root@hadoop101.yinzhengjie.org.cn ~]# hdfs dfs -ls /yinzhengjie/myFile.har
Found 4 items
-rw-r--r--   3 root supergroup          0 2020-03-17 23:21 /yinzhengjie/myFile.har/_SUCCESS
-rw-r--r--   3 root supergroup        726 2020-03-17 23:21 /yinzhengjie/myFile.har/_index
-rw-r--r--   3 root supergroup         23 2020-03-17 23:21 /yinzhengjie/myFile.har/_masterindex
-rw-r--r--   3 root supergroup      11598 2020-03-17 23:21 /yinzhengjie/myFile.har/part-0
[root@hadoop101.yinzhengjie.org.cn ~]# 
[root@hadoop101.yinzhengjie.org.cn ~]# hdfs dfs -ls /yinzhengjie/myFile.har
[root@hadoop101.yinzhengjie.org.cn ~]# hdfs dfs -ls /yinzhengjie/myFile.har
Found 4 items
-rw-r--r--   3 root supergroup          0 2020-03-17 23:21 /yinzhengjie/myFile.har/_SUCCESS
-rw-r--r--   3 root supergroup        726 2020-03-17 23:21 /yinzhengjie/myFile.har/_index
-rw-r--r--   3 root supergroup         23 2020-03-17 23:21 /yinzhengjie/myFile.har/_masterindex
-rw-r--r--   3 root supergroup      11598 2020-03-17 23:21 /yinzhengjie/myFile.har/part-0
[root@hadoop101.yinzhengjie.org.cn ~]# 
[root@hadoop101.yinzhengjie.org.cn ~]# 
[root@hadoop101.yinzhengjie.org.cn ~]# hdfs dfs -ls har:///yinzhengjie/myFile.har
Found 7 items
-rw-r--r--   3 root supergroup       1664 2020-03-17 23:20 har:///yinzhengjie/myFile.har/CentOS-Base.repo
-rw-r--r--   3 root supergroup       1309 2020-03-17 23:20 har:///yinzhengjie/myFile.har/CentOS-CR.repo
-rw-r--r--   3 root supergroup        649 2020-03-17 23:20 har:///yinzhengjie/myFile.har/CentOS-Debuginfo.repo
-rw-r--r--   3 root supergroup        630 2020-03-17 23:20 har:///yinzhengjie/myFile.har/CentOS-Media.repo
-rw-r--r--   3 root supergroup       1331 2020-03-17 23:20 har:///yinzhengjie/myFile.har/CentOS-Sources.repo
-rw-r--r--   3 root supergroup       5701 2020-03-17 23:20 har:///yinzhengjie/myFile.har/CentOS-Vault.repo
-rw-r--r--   3 root supergroup        314 2020-03-17 23:20 har:///yinzhengjie/myFile.har/CentOS-fasttrack.repo
[root@hadoop101.yinzhengjie.org.cn ~]# 
[root@hadoop101.yinzhengjie.org.cn ~]# 
[root@hadoop101.yinzhengjie.org.cn ~]# hdfs dfs -ls har:///yinzhengjie/myFile.har          #查看har包归档文件的内容

3>.解压归档文件

[root@hadoop101.yinzhengjie.org.cn ~]# hdfs dfs -ls /yinzhengjie/
Found 2 items
drwxrwx---   - root supergroup          0 2020-03-12 16:51 /yinzhengjie/jobhistory
drwxr-xr-x   - root supergroup          0 2020-03-17 23:21 /yinzhengjie/myFile.har
[root@hadoop101.yinzhengjie.org.cn ~]# 
[root@hadoop101.yinzhengjie.org.cn ~]# hdfs dfs -ls /yinzhengjie/myFile.har
Found 4 items
-rw-r--r--   3 root supergroup          0 2020-03-17 23:21 /yinzhengjie/myFile.har/_SUCCESS
-rw-r--r--   3 root supergroup        726 2020-03-17 23:21 /yinzhengjie/myFile.har/_index
-rw-r--r--   3 root supergroup         23 2020-03-17 23:21 /yinzhengjie/myFile.har/_masterindex
-rw-r--r--   3 root supergroup      11598 2020-03-17 23:21 /yinzhengjie/myFile.har/part-0
[root@hadoop101.yinzhengjie.org.cn ~]# 
[root@hadoop101.yinzhengjie.org.cn ~]# hadoop fs -cp har:///yinzhengjie/myFile.har/* /yinzhengjie/
[root@hadoop101.yinzhengjie.org.cn ~]# 
[root@hadoop101.yinzhengjie.org.cn ~]# hdfs dfs -ls /yinzhengjie/
Found 9 items
-rw-r--r--   3 root supergroup       1664 2020-03-17 23:28 /yinzhengjie/CentOS-Base.repo
-rw-r--r--   3 root supergroup       1309 2020-03-17 23:28 /yinzhengjie/CentOS-CR.repo
-rw-r--r--   3 root supergroup        649 2020-03-17 23:28 /yinzhengjie/CentOS-Debuginfo.repo
-rw-r--r--   3 root supergroup        630 2020-03-17 23:28 /yinzhengjie/CentOS-Media.repo
-rw-r--r--   3 root supergroup       1331 2020-03-17 23:28 /yinzhengjie/CentOS-Sources.repo
-rw-r--r--   3 root supergroup       5701 2020-03-17 23:28 /yinzhengjie/CentOS-Vault.repo
-rw-r--r--   3 root supergroup        314 2020-03-17 23:28 /yinzhengjie/CentOS-fasttrack.repo
drwxrwx---   - root supergroup          0 2020-03-12 16:51 /yinzhengjie/jobhistory
drwxr-xr-x   - root supergroup          0 2020-03-17 23:21 /yinzhengjie/myFile.har
[root@hadoop101.yinzhengjie.org.cn ~]# 
[root@hadoop101.yinzhengjie.org.cn ~]# hdfs dfs -ls /yinzhengjie/myFile.har
Found 4 items
-rw-r--r--   3 root supergroup          0 2020-03-17 23:21 /yinzhengjie/myFile.har/_SUCCESS
-rw-r--r--   3 root supergroup        726 2020-03-17 23:21 /yinzhengjie/myFile.har/_index
-rw-r--r--   3 root supergroup         23 2020-03-17 23:21 /yinzhengjie/myFile.har/_masterindex
-rw-r--r--   3 root supergroup      11598 2020-03-17 23:21 /yinzhengjie/myFile.har/part-0
[root@hadoop101.yinzhengjie.org.cn ~]# 
[root@hadoop101.yinzhengjie.org.cn ~]# 
[root@hadoop101.yinzhengjie.org.cn ~]# hadoop fs -cp har:///yinzhengjie/myFile.har/* /yinzhengjie/

 

posted @ 2020-03-10 23:12  JasonYin2020  阅读(1084)  评论(0编辑  收藏  举报