zoukankan      html  css  js  c++  java
  • hadoop之hdfs命令详解

    本篇主要对hadoop命令和hdfs命令进行阐述,yarn命令会在之后的文章中体现

        hadoop fs命令可以用于其他文件系统,不止是hdfs文件系统内,也就是说该命令的使用范围更广可以用于HDFS、Local FS等不同的文件系统。而hdfs dfs命令只用于HDFS文件系统;

    一、hadoop命令

    使用语法:hadoop [--config confdir] COMMAND #其中config用来覆盖默认的配置

    ##command #子命令
    fs                   run a generic filesystem user client
    version              print the version
    jar <jar>            run a jar file
    checknative [-a|-h]  check native hadoop and compression libraries availability
    distcp <srcurl> <desturl> copy file or directories recursively
    archive -archiveName NAME -p <parent path> <src>* <dest> create a hadoop archive
    classpath            prints the class path needed to get the
    credential           interact with credential providers Hadoop jar and the required libraries
    daemonlog            get/set the log level for each daemon
    s3guard              manage data on S3
    trace                view and modify Hadoop tracing settings

    1、archive 

    创建一个hadoop压缩文件,详细的可以参考 http://hadoop.apache.org/docs/r2.7.0/hadoop-archives/HadoopArchives.html

    使用格式:hadoop archive -archiveName NAME -p <parent path> <src>* <dest>  #-p 可以同时指定多个路径

    实例:

    [hive@mwpl003 ~]$ hadoop fs -touchz /tmp/test/a.txt
    [hive@mwpl003 ~]$ hadoop fs -ls /tmp/test/
    Found 1 items
    -rw-r--r--   3 hive supergroup          0 2019-09-18 13:50 /tmp/test/a.txt
    [hive@mwpl003 ~]$ hadoop archive -archiveName test.har -p  /tmp/test/a.txt -r 3 /tmp/test
    19/09/18 13:52:58 INFO mapreduce.JobSubmitter: number of splits:1
    19/09/18 13:52:58 INFO mapreduce.JobSubmitter: Submitting tokens for job: job_1565571819971_6988
    19/09/18 13:52:58 INFO impl.YarnClientImpl: Submitted application application_1565571819971_6988
    19/09/18 13:52:58 INFO mapreduce.Job: The url to track the job: http://ip_address:8088/proxy/application_1565571819971_6988/
    19/09/18 13:52:58 INFO mapreduce.Job: Running job: job_1565571819971_6988
    19/09/18 13:53:04 INFO mapreduce.Job: Job job_1565571819971_6988 running in uber mode : false
    19/09/18 13:53:04 INFO mapreduce.Job:  map 0% reduce 0%
    19/09/18 13:53:08 INFO mapreduce.Job:  map 100% reduce 0%
    19/09/18 13:53:13 INFO mapreduce.Job:  map 100% reduce 100%
    19/09/18 13:53:13 INFO mapreduce.Job: Job job_1565571819971_6988 completed successfully
    19/09/18 13:53:13 INFO mapreduce.Job: Counters: 49
            File System Counters
                    FILE: Number of bytes read=80
                    FILE: Number of bytes written=313823
                    FILE: Number of read operations=0
                    FILE: Number of large read operations=0
                    FILE: Number of write operations=0
                    HDFS: Number of bytes read=264
                    HDFS: Number of bytes written=69
                    HDFS: Number of read operations=14
                    HDFS: Number of large read operations=0
                    HDFS: Number of write operations=8
            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)=7977
                    Total time spent by all reduces in occupied slots (ms)=12015
                    Total time spent by all map tasks (ms)=2659
                    Total time spent by all reduce tasks (ms)=2403
                    Total vcore-milliseconds taken by all map tasks=2659
                    Total vcore-milliseconds taken by all reduce tasks=2403
                    Total megabyte-milliseconds taken by all map tasks=8168448
                    Total megabyte-milliseconds taken by all reduce tasks=12303360
            Map-Reduce Framework
                    Map input records=1
                    Map output records=1
                    Map output bytes=59
                    Map output materialized bytes=76
                    Input split bytes=97
                    Combine input records=0
                    Combine output records=0
                    Reduce input groups=1
                    Reduce shuffle bytes=76
                    Reduce input records=1
                    Reduce output records=0
                    Spilled Records=2
                    Shuffled Maps =1
                    Failed Shuffles=0
                    Merged Map outputs=1
                    GC time elapsed (ms)=91
                    CPU time spent (ms)=2320
                    Physical memory (bytes) snapshot=1189855232
                    Virtual memory (bytes) snapshot=11135381504
                    Total committed heap usage (bytes)=3043491840
            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=167
            File Output Format Counters 
                    Bytes Written=0
    [hive@mwpl003 ~]$ hadoop fs -ls /tmp/test/
    Found 2 items
    -rw-r--r--   3 hive supergroup          0 2019-09-18 13:50 /tmp/test/a.txt
    drwxr-xr-x   - hive supergroup          0 2019-09-18 13:53 /tmp/test/test.har
    
    [hive@mwpl003 ~]$ hadoop fs -ls /tmp/test/test.har/
    Found 4 items
    -rw-r--r--   3 hive supergroup          0 2019-09-18 13:53 /tmp/test/test.har/_SUCCESS
    -rw-r--r--   3 hive supergroup         55 2019-09-18 13:53 /tmp/test/test.har/_index
    -rw-r--r--   3 hive supergroup         14 2019-09-18 13:53 /tmp/test/test.har/_masterindex
    -rw-r--r--   3 hive supergroup          0 2019-09-18 13:53 /tmp/test/test.har/part-0
    
    解压:
    hadoop distcp har:///tmp/test/test.har /tmp/test1
    hdfs dfs -cp har:///tmp/test/test.har /tmp/test1

    2、checknative

    检查hadoop的原生代码,一般人用不到

    使用语法:hadoop checknative [-a] [-h]
    -a 检查所有的库
    -h 显示帮助

    3、classpath

    打印hadoop jar或者库的类路径

    使用语法:hadoop classpath [--glob |--jar <path> |-h |--help]

    4、credential

    管理凭证供应商的凭证、密码和secret(有关秘密信息)

    使用语法:hadoop credential <subcommand> [options]

    5、distcp(比较常用)

    distributed copy的缩写(望文生义),主要用于集群内/集群之间 复制文件。需要使用到mapreduce

    使用语法:hadoop distcp [-option] hdfs://source hdfs://dest
    详细见:http://hadoop.apache.org/docs/r2.7.0/hadoop-distcp/DistCp.html

    常用的几个选项:
    -m <num_maps>  #指定了拷贝数据时map的数目。请注意并不是map数越多吞吐量越大
    -i               #忽略失败
    -log <logdir>  #记录日志到 <logdir>
    -update        #当目标集群上的文件不存在或文件不一致时,才会从源集群拷贝
    -overwrite     #覆盖目标集群上的文件
    -filter        #过滤不需要复制的文件
    -delete        #删除目标文件存在,但不存在source中的文件

    6、fs

    与hdfs dfs同用

    查看帮助:hadoop fs -help

    详细查看:http://hadoop.apache.org/docs/r2.7.0/hadoop-project-dist/hadoop-common/FileSystemShell.html

    包括如下一些子命令:

    appendToFile, cat, checksum, chgrp, chmod, chown, copyFromLocal, copyToLocal, count, cp, createSnapshot, deleteSnapshot, df, du, expunge, find, get, getfacl, getfattr, getmerge, help, ls, mkdir, moveFromLocal, moveToLocal, mv, put, renameSnapshot, rm, rmdir, setfacl, setfattr, setrep, stat, tail, test, text, touchz

    在这里我想各位都应该比较熟悉linux的基本操作命令了,所以这些命令用起来比较简单

    6.1、appendToFile

    appendToFile  #追加一下本地文件到分布式文件系统
    Usage: hadoop fs -appendToFile <localsrc> ... <dst>
    example:
    hadoop fs -appendToFile localfile1 localfile2 /user/hadoop/hadoopfile
    hadoop fs -appendToFile - hdfs://nn.example.com/hadoop/hadoopfile  #表示从标准输入输入数据到hadoopfile中,ctrl+d 结束输入

    6.2、cat

    cat   #查看文件内容
    Usage: hadoop fs -cat URI [URI ...]
    example:
    hadoop fs -cat hdfs://nn1.example.com/file1 hdfs://nn2.example.com/file2
    hadoop fs -cat file:///file3 /user/hadoop/file4

    6.3、checksum

    checksum  #返回被检查文件的格式
    Usage: hadoop fs -checksum URI
    example:
    [hive@mwpl003 ~]$  hadoop fs -checksum /tmp/test/test.txt
    /tmp/test/test.txt      MD5-of-0MD5-of-512CRC32C        000002000000000000000000fde199c1517b7b26b0565ff6b0f46acc

    6.4、chgrp 

    chgrp   #变更文件目录的所属组
    Usage: hadoop fs -chgrp [-R] GROUP URI [URI ...]

    6.5、chmod

    chmod  #修改文件或者目录的权限
    Usage: hadoop fs -chmod [-R] <MODE[,MODE]... | OCTALMODE> URI [URI ...]

    6.6、chown

    chown  #修改目录或者文件的拥有者和所属组
    Usage: hadoop fs -chown [-R] [OWNER][:[GROUP]] URI [URI ]

    6.7、copyFromLocal

    copyFromLocal #从本地复制文件或者文件夹到hdfs,类似put命令
    Usage: hadoop fs -copyFromLocal [-f] <localsrc> URI  #其中-f选项会覆盖与原文件一样的目标路径文件
    example:
    hadoop fs -copyFromLocal start-hadoop.sh  /tmp

    6.8、copyToLocal

    copyToLocal  #类似get命令,从hdfs获取文件到本地
    Usage: hadoop fs -copyToLocal [-ignorecrc] [-crc] URI <localdst>

    6.9、count

    count  #计算 目录,文件,字节数
    Usage: hadoop fs -count [-q] [-h] [-v] <paths>  

    6.10、cp

    cp     #复制源文件到目标文件
    Usage: hadoop fs -cp [-f] [-p | -p[topax]] URI [URI ...] <dest>
    Example:
    hadoop fs -cp /user/hadoop/file1 /user/hadoop/file2
    hadoop fs -cp /user/hadoop/file1 /user/hadoop/file2 /user/hadoop/dir

    6.11、Snapshot相关

    createSnapshot #创建快照
    deleteSnapshot #删除快照
    详细见:http://hadoop.apache.org/docs/r2.8.0/hadoop-project-dist/hadoop-hdfs/HdfsSnapshots.html
    HDFS快照是文件系统的只读时间点副本。可以在文件系统的子树或整个文件系统上拍摄快照。快照的一些常见用例是数据备份,防止用户错误和灾难恢复。
    在创建快照前,要设置一个目录为snapshottable(需要管理员权限),表示可以在该目录中创建快照
    hdfs dfsadmin -allowSnapshot <path> #在path中启用快照
    hdfs dfsadmin -disallowSnapshot <path> #在path中禁止快照
    hdfs dfs -ls /foo/.snapshot #列出快照目录下的所有快照
    hdfs dfs -createSnapshot <path> [<snapshotName>] #创建快照,快照名默认为时间戳格式
    hdfs dfs -deleteSnapshot <path> <snapshotName> #删除快照
    hdfs dfs -renameSnapshot <path> <oldName> <newName> #快照重命名
    hdfs lsSnapshottableDir #获取快照目录

    6.12、df

    df  #展示空间使用情况
    Usage: hadoop fs -df [-h] URI [URI ...]

    6.13、du

    du  #展示目录包含的文件的大小
    Usage: hadoop fs -du [-s] [-h] URI [URI ...]
    Example:
    hadoop fs -du /user/hadoop/dir1 /user/hadoop/file1 hdfs://nn.example.com/user/hadoop/dir1

    6.14、expunge

    expunge  #清空回收站(不要瞎用)
    Usage: hadoop fs -expunge

    6.15、find

    find   #查找
    Usage: hadoop fs -find <path> ... <expression> ...
    -name pattern
    -iname pattern #忽略大小写
    -print
    -print0Always
    Example:
    hadoop fs -find / -name test -print

    6.16、get

    get #获取数据,类似于copyToLocal.但有crc校验
    Usage: hadoop fs -get [-ignorecrc] [-crc] <src> <localdst>
    Example:
    hadoop fs -get /tmp/input/hadoop/*.xml /home/hadoop/testdir/

    6.17、getfacl

    getfacl #展示目录或者文件的ACL权限
    Usage: hadoop fs -getfacl [-R] <path>
    [hive@mwpl003 ~]$ hadoop fs -getfacl -R  /tmp/test
    # file: /tmp/test
    # owner: hive
    # group: supergroup
    getfacl: The ACL operation has been rejected.  Support for ACLs has been disabled by setting dfs.namenode.acls.enabled to false.

    6.18、getfattr

    getfattr #显示文件或目录的扩展属性名称和值
    Usage: hadoop fs -getfattr [-R] -n name | -d [-e en] <path>
    -n name和 -d是互斥的,
    -d表示获取所有属性。
    -R表示循环获取; 
    -e en 表示对获取的内容编码,en的可以取值是 “text”, “hex”, and “base64”.
    Examples:
    hadoop fs -getfattr -d /file
    hadoop fs -getfattr -R -n user.myAttr /dir

    6.19、getmerge 

    getmerge  #合并文件
    Usage: hadoop fs -getmerge <src> <localdst> [addnl]
    hadoop fs -getmerge   /src  /opt/output.txt
    hadoop fs -getmerge  /src/file1.txt /src/file2.txt  /output.txt

    6.20、ls

    ls   #罗列文件
    Usage: hadoop fs -ls [-d] [-h] [-R] [-t] [-S] [-r] [-u] <args>

    6.21、mkdir 

    mkdir #创建文件夹
    Usage: hadoop fs -mkdir [-p] <paths>
    Example:
    hadoop fs -mkdir /user/hadoop/dir1 /user/hadoop/dir2
    hadoop fs -mkdir hdfs://nn1.example.com/user/hadoop/dir hdfs://nn2.example.com/user/hadoop/dir

    6.22、moveFromLocal

    moveFromLocal #把本地文件移动到hdfs上
    Usage: hadoop fs -moveFromLocal <localsrc> <dst>

    6.23、moveToLocal

    moveToLocal   #把hdfs文件移动到本地上
    Usage: hadoop fs -moveToLocal [-crc] <src> <dst>

    6.24、mv

    mv   #移动文件,但是可以一次移动多个
    Usage: hadoop fs -mv URI [URI ...] <dest>
    Example:
    hadoop fs -mv /user/hadoop/file1 /user/hadoop/file2
    hadoop fs -mv hdfs://nn.example.com/file1 hdfs://nn.example.com/file2 hdfs://nn.example.com/file3 hdfs://nn.example.com/dir1

    6.25、put

    put  #把文件复制到hdfs上
    Usage: hadoop fs -put <localsrc> ... <dst>
    hadoop fs -put localfile hdfs://nn.example.com/hadoop/hadoopfile
    hadoop fs -put - hdfs://nn.example.com/hadoop/hadoopfile  #Reads the input from stdin.

    6.26、rm

    rm  #删除文件
    Usage: hadoop fs -rm [-f] [-r |-R] [-skipTrash] URI [URI ...]

    6.27、rmdir

    rmdir  #删除一个目录
    Usage: hadoop fs -rmdir [--ignore-fail-on-non-empty] URI [URI ...]

    6.28、setfacl

    setfacl  #设置ACL权限
    Usage: hadoop fs -setfacl [-R] [-b |-k -m |-x <acl_spec> <path>] |[--set <acl_spec> <path>]
    -b 删除除基本acl项之外的所有项。保留用户、组和其他用户
    -k 删除所有的默认ACL权限
    -R 递归操作
    -m 修改ACL权限,保留旧的,添加新的
    -x 删除指定ACL权限
    --set 完全替换现有的ACL权限
    Examples:
    hadoop fs -setfacl -m user:hadoop:rw- /file
    hadoop fs -setfacl -x user:hadoop /file
    hadoop fs -setfacl -b /file
    hadoop fs -setfacl -k /dir
    hadoop fs -setfacl --set user::rw-,user:hadoop:rw-,group::r--,other::r-- /file
    hadoop fs -setfacl -R -m user:hadoop:r-x /dir
    hadoop fs -setfacl -m default:user:hadoop:r-x /dir 

    6.29、setfattr 

    setfattr  #设置额外的属性
    Usage: hadoop fs -setfattr -n name [-v value] | -x name <path>
    -b 删除除基本acl项之外的所有项。保留用户、组和其他用户
    -n 额外属性名
    -v 额外属性值
    -x name 删除额外属性
    Examples:
    hadoop fs -setfattr -n user.myAttr -v myValue /file
    hadoop fs -setfattr -n user.noValue /file
    hadoop fs -setfattr -x user.myAttr /file

    6.30、setrep 

    setrep  #改变文件的复制因子(复本)
    Usage: hadoop fs -setrep [-R] [-w] <numReplicas> <path>
    Example:
    hadoop fs -setrep -w 3 /user/hadoop/dir1

    6.31、stat

    stat #获取文件的时间
    Usage: hadoop fs -stat [format] <path> ...
    Example:
    hadoop fs -stat "%F %u:%g %b %y %n" /file

    6.32、tail

    tail #展示文件到标准输出
    Usage: hadoop fs -tail [-f] URI

    6.33、test

    test  #测试
    Usage: hadoop fs -test -[defsz] URI
    -d 判断是否是目录
    -e 判断是否存在
    -f 判断是否是文件
    -s 判断目录是否为空
    -z 判断文件是否为空
    Example:
    hadoop fs -test -e filename

    6.34、text

    text #可以用来看压缩文件
    Usage: hadoop fs -text <src>

    6.35、touchz

    touchz  #创建一个空文件
    Usage: hadoop fs -touchz URI [URI ...]

    7、jar

    jar  #运行一个jar文件
    Usage: hadoop jar <jar> [mainClass] args...
    Example:
    hadoop jar ./test/wordcount/wordcount.jar org.codetree.hadoop.v1.WordCount /test/chqz/input /test/chqz/output的各段的含义:
    (1) hadoop:${HADOOP_HOME}/bin下的shell脚本名。
    (2) jar:hadoop脚本需要的command参数。
    (3) ./test/wordcount/wordcount.jar:要执行的jar包在本地文件系统中的完整路径,参递给RunJar类。
    (4) org.codetree.hadoop.v1.WordCount:main方法所在的类,参递给RunJar类。
    (5) /test/chqz/input:传递给WordCount类,作为DFS文件系统的路径,指示输入数据来源。
    (6) /test/chqz/output:传递给WordCount类,作为DFS文件系统的路径,指示输出数据路径。
    hadoop推荐使用yarn jar替代hadoop jar 详情见:http://hadoop.apache.org/docs/r2.8.0/hadoop-yarn/hadoop-yarn-site/YarnCommands.html#jar

    8、key

    key #用来管理秘钥,基本不用

    9、trace

    trace  #查看和修改跟踪设置
    详情见:http://hadoop.apache.org/docs/r2.8.0/hadoop-project-dist/hadoop-common/Tracing.html

    二、hdfs命令

    hdfs命令有如下选项:

    User Commands: classpath, dfs, fetchdt, fsck, getconf, groups, lsSnapshottableDir, jmxget, oev, oiv, oiv_legacy, snapshotDiff, version,
    Administration Commands: balancer, cacheadmin, crypto, datanode, dfsadmin, haadmin, journalnode, mover, namenode, nfs3, portmap, secondarynamenode, storagepolicies, zkfc
    Debug Commands: verifyMeta, computeMeta, recoverLease

    这里不全详解,详情见:http://hadoop.apache.org/docs/r2.8.0/hadoop-project-dist/hadoop-hdfs/HDFSCommands.html 

    1、classpath

    classpath  #获取jar包或者库的有关类路径
    Usage: hdfs classpath [--glob |--jar <path> |-h |--help]

    2、dfs

    dfs #同上节hadoop fs 命令

    3、fetchdt

    fetchdt  #从namenode节点获取代理令牌
    Usage: hdfs fetchdt <opts> <token_file_path>
    详情见:http://hadoop.apache.org/docs/r2.8.0/hadoop-project-dist/hadoop-hdfs/HdfsUserGuide.html#fetchdt

    4、fsck(重要)

    hdfs fsck <path>
              [-list-corruptfileblocks |
              [-move | -delete | -openforwrite]
              [-files [-blocks [-locations | -racks | -replicaDetails]]]
              [-includeSnapshots]
              [-storagepolicies] [-blockId <blk_Id>]
    
    -delete    删除损坏的文件
    -files    打印正在检查的文件.
    -files -blocks    打印块报告
    -files -blocks -locations    Print out locations for every block.
    -files -blocks -racks    打印每个块的位置
    -files -blocks -replicaDetails    打印出每个副本的详细信息.
    -includeSnapshots    如果给定路径指示SnapshotTable目录或其下有SnapshotTable目录,则包括快照数据
    -list-corruptfileblocks    打印出所属丢失块和文件的列表.
    -move    将损坏的文件移动到/lost+found.
    -openforwrite    打印为写入而打开的文件.
    -storagepolicies    打印块的存储策略摘要.
    -blockId    打印出有关块的信息.

    5、getconf(重要)

    hdfs getconf -namenodes #获取namenode节点
    hdfs getconf -secondaryNameNodes #获取secondaryNameNodes节点
    hdfs getconf -backupNodes  #获取群集中备份节点的列表
    hdfs getconf -includeFile  #获取定义可以加入群集的数据节点的包含文件路径
    hdfs getconf -excludeFile  #获取定义需要停用的数据节点的排除文件路径
    hdfs getconf -nnRpcAddresses #获取namenode rpc地址
    hdfs getconf -confKey [key] #从配置中获取特定密钥 ,可以用来返回hadoop的配置信息的具体值

    6、groups

    groups #返回用户的所属组
    Usage: hdfs groups [username ...]

    7、lsSnapshottableDir

    lsSnapshottableDir #查看快照目录
    Usage: hdfs lsSnapshottableDir [-help]

    8、jmxget 

    jmxget  #从特定服务获取jmx信息
    Usage: hdfs jmxget [-localVM ConnectorURL | -port port | -server mbeanserver | -service service]

    9、oev 

    oev  #离线编辑查看器
    Usage: hdfs oev [OPTIONS] -i INPUT_FILE -o OUTPUT_FILE

    10、oiv

    oiv  #离线映像编辑查看器
    Usage: hdfs oiv [OPTIONS] -i INPUT_FILE

    11、snapshotDiff

    snapshotDiff  #对比快照信息的不同
    Usage: hdfs snapshotDiff <path> <fromSnapshot> <toSnapshot>
    详情见:http://hadoop.apache.org/docs/r2.8.0/hadoop-project-dist/hadoop-hdfs/HdfsSnapshots.html#Get_Snapshots_Difference_Report

    12、balancer(重要)

    balancer
     hdfs balancer
              [-threshold <threshold>]
              [-policy <policy>]
              [-exclude [-f <hosts-file> | <comma-separated list of hosts>]]
              [-include [-f <hosts-file> | <comma-separated list of hosts>]]
              [-source [-f <hosts-file> | <comma-separated list of hosts>]]
              [-blockpools <comma-separated list of blockpool ids>]
              [-idleiterations <idleiterations>]
    -policy <policy>    datanode (default): 如果每个数据节点都是平衡的,则群集是平衡的.
    blockpool: 如果每个数据节点中的每个块池都是平衡的,则群集是平衡的.
    -threshold <threshold>    磁盘容量的百分比。这将覆盖默认阈值
    -exclude -f <hosts-file> | <comma-separated list of hosts>    排除平衡器正在平衡的指定数据节点
    -include -f <hosts-file> | <comma-separated list of hosts>    仅包含要由平衡器平衡的指定数据节点
    -source -f <hosts-file> | <comma-separated list of hosts>    仅选取指定的数据节点作为源节点。
    -blockpools <comma-separated list of blockpool ids>    平衡器将仅在此列表中包含的块池上运行.
    -idleiterations <iterations>    退出前的最大空闲迭代次数。这将覆盖默认的空闲操作(5次)

    13、cacheadmin

    cacheadmin
    Usage: hdfs cacheadmin -addDirective -path <path> -pool <pool-name> [-force] [-replication <replication>] [-ttl <time-to-live>]
    hdfs crypto -createZone -keyName <keyName> -path <path>
      hdfs crypto -listZones
      hdfs crypto -provisionTrash -path <path>
      hdfs crypto -help <command-name>
    详情见:http://hadoop.apache.org/docs/r2.8.0/hadoop-project-dist/hadoop-hdfs/CentralizedCacheManagement.html

    14、datanode

    datanode #运行datanode
    Usage: hdfs datanode [-regular | -rollback | -rollingupgrade rollback]
    -regular    正常启动(default).
    -rollback    将datanode回滚到以前的版本。这应该在停止datanode并分发旧的hadoop版本之后使用
    -rollingupgrade rollback    回滚滚动升级操作

    15、dfsadmim(重要)

    hdfs dfsadmin [GENERIC_OPTIONS]
              [-report [-live] [-dead] [-decommissioning]]   #报告基本的文件系统信息和统计信息,包括测量所有dns上的复制、校验和、快照等使用的原始空间。
              [-safemode enter | leave | get | wait | forceExit] #安全模式维护命令
               #安全模式在namenode启动时自动进入,当配置的最小块百分比满足最小复制条件时自动离开安全模式。如果namenode检测到任何异常,
               #则它将在安全模式下逗留,直到该问题得到解决。如果异常是故意操作的结果,那么管理员可以使用-safemode forceExit退出安全模式
              [-saveNamespace] #将当前命名空间保存到存储目录并重置编辑日志。需要安全模式
              [-rollEdits] #在活动的namenode上滚动编辑日志
              [-restoreFailedStorage true |false |check] #此选项将打开或者关闭自动尝试还原失败的存储副本。如果失败的存储再次可用,
              #系统将在检查点期间尝试还原编辑和fsimage。“check”选项将返回当前设置
              [-refreshNodes] #重新读取主机并排除文件,以更新允许连接到namenode的数据节点集,以及应解除或重新启用的数据节点集
              [-setQuota <quota> <dirname>...<dirname>]
              [-clrQuota <dirname>...<dirname>]
              [-setSpaceQuota <quota> [-storageType <storagetype>] <dirname>...<dirname>]
              [-clrSpaceQuota [-storageType <storagetype>] <dirname>...<dirname>]
              [-finalizeUpgrade] #完成hdfs的升级。datanodes删除它们以前版本的工作目录,然后namenode执行相同的操作。这就完成了升级过程
              [-rollingUpgrade [<query> |<prepare> |<finalize>]]
              [-metasave filename] #将namenode的主数据结构保存到hadoop.log.dir属性指定的目录中的filename。如果文件名存在,它将被覆盖。
              #该文件包含带namenode的datanodes心跳,等待复制的块,当前正在复制的块,等待删除的块
              [-refreshServiceAcl] #重新加载服务级别授权策略文件
              [-refreshUserToGroupsMappings] #刷新用户到组的映射
              [-refreshSuperUserGroupsConfiguration] #刷新超级用户代理组映射
              [-refreshCallQueue] #从配置重新加载调用队列
              [-refresh <host:ipc_port> <key> [arg1..argn]] #触发由<host:ipc port>上的<key>指定的资源的运行时刷新。之后的所有其他参数都将发送到主机
              [-reconfig <datanode |...> <host:ipc_port> <start |status>] #开始重新配置或获取正在进行的重新配置的状态。第二个参数指定节点类型。目前,只支持重新加载datanode的配置
              [-printTopology] #打印由namenode报告的机架及其节点的树
              [-refreshNamenodes datanodehost:port] #对于给定的数据节点,重新加载配置文件,停止为已删除的块池提供服务,并开始为新的块池提供服务
              [-deleteBlockPool datanode-host:port blockpoolId [force]] #如果传递了force,则将删除给定数据节点上给定block pool id的块池目录及其内容,否则仅当该目录为空时才删除该目录。
              #如果datanode仍在为块池提供服务,则该命令将失败
              [-setBalancerBandwidth <bandwidth in bytes per second>] #更改HDFS块平衡期间每个数据节点使用的网络带宽。<bandwidth>是每个数据节点每秒将使用的最大字节数。
              #此值重写dfs.balance.bandwidthpersec参数。注意:新值在datanode上不是持久的
              [-getBalancerBandwidth <datanode_host:ipc_port>] #获取给定数据节点的网络带宽(字节/秒)。这是数据节点在hdfs块平衡期间使用的最大网络带宽
              [-allowSnapshot <snapshotDir>] #设置快照目录
              [-disallowSnapshot <snapshotDir>] #禁止快照
              [-fetchImage <local directory>] #从namenode下载最新的fsimage并将其保存在指定的本地目录中
              [-shutdownDatanode <datanode_host:ipc_port> [upgrade]] #提交给定数据节点的关闭请求
              [-getDatanodeInfo <datanode_host:ipc_port>] #获取有关给定数据节点的信息
              [-evictWriters <datanode_host:ipc_port>]  #使datanode收回正在写入块的所有客户端。如果由于编写速度慢而挂起退役,这将非常有用
              [-triggerBlockReport [-incremental] <datanode_host:ipc_port>] #触发给定数据节点的块报告。如果指定了“增量”,则为“增量”,否则为完整的块报告
              [-help [cmd]]

    16、haadmin(重要)

    hdfs haadmin -checkHealth <serviceId>  #检查给定namenode的运行状况
    hdfs haadmin -failover [--forcefence] [--forceactive] <serviceId> <serviceId> #在两个namenodes之间启动故障转移
    hdfs haadmin -getServiceState <serviceId> #确定给定的namenode是活动的还是备用的
    hdfs haadmin -help <command>
    hdfs haadmin -transitionToActive <serviceId> [--forceactive] #将给定namenode的状态转换为active
    hdfs haadmin -transitionToStandby <serviceId> #将给定namenode的状态转换为standby
    详情见:http://hadoop.apache.org/docs/r2.8.0/hadoop-project-dist/hadoop-hdfs/HDFSHighAvailabilityWithNFS.html

    17、journalnode

    journalnode #为通过QJM实现的高可用hdfs启动journalnode
    Usage: hdfs journalnode
    

    18、mover  

    Usage: hdfs mover [-p <files/dirs> | -f <local file name>]
    -f 指定包含要迁移的hdfs文件/目录列表的本地文件
    -p 指定要迁移的hdfs文件/目录的空间分隔列表
    详情见:http://hadoop.apache.org/docs/r2.8.0/hadoop-project-dist/hadoop-hdfs/ArchivalStorage.html

    19、namenode

    namenode
    hdfs namenode [-backup] |  #开始备份节点
             [-checkpoint] | #检查点开始节点
             [-format [-clusterid cid ] [-force] [-nonInteractive] ] |  #格式化指定的NameNode。 它启动NameNode,
             #对其进行格式化然后将其关闭。 如果名称目录存在,则为-force选项格式。 如果名称目录存在,则-nonInteractive选项将中止,除非指定了-force选项
             [-upgrade [-clusterid cid] [-renameReserved<k-v pairs>] ] | #在分发新的Hadoop版本后,应该使用升级选项启动Namenode
             [-upgradeOnly [-clusterid cid] [-renameReserved<k-v pairs>] ] | #升级指定的NameNode然后关闭它
             [-rollback] | #将NameNode回滚到以前的版本。 应在停止群集并分发旧Hadoop版本后使用此方法
             [-rollingUpgrade <rollback |started> ] |#滚动升级 详情见:http://hadoop.apache.org/docs/r2.8.0/hadoop-project-dist/hadoop-hdfs/HdfsRollingUpgrade.html
             [-finalize] |  #不再支持。使用dfsadmin -finalizeUpgrade替换
             [-importCheckpoint] | #从检查点目录加载image并将其保存到当前目录中。 从属性dfs.namenode.checkpoint.dir读取检查点目录
             [-initializeSharedEdits] | #格式化新的共享编辑目录并复制足够的编辑日志段,以便备用NameNode可以启动
             [-bootstrapStandby [-force] [-nonInteractive] [-skipSharedEditsCheck] ] | #允许通过从活动NameNode复制最新的命名空间快照来引导备用NameNode的存储目录
             [-recover [-force] ] | #在损坏的文件系统上恢复丢失的元数据
             [-metadataVersion ] #验证配置的目录是否存在,然后打印软件和映像的元数据版本

    20、secondarynamenode

    Usage: hdfs secondarynamenode [-checkpoint [force]] | [-format] | [-geteditsize]
    -checkpoint [force]    如果EditLog size> = fs.checkpoint.size,则检查SecondaryNameNode。 如果使用force,则检查点与EditLog大小无关
    -format    启动期间格式化本地存储
    -geteditsize    打印NameNode上未取消选中的事务的数量

    21、storagepolicies

    storagepolicies #列出所有存储策略
    Usage: hdfs storagepolicies
    详情见:http://hadoop.apache.org/docs/r2.8.0/hadoop-project-dist/hadoop-hdfs/ArchivalStorage.html
    

    22、zkfc

    Usage: hdfs zkfc [-formatZK [-force] [-nonInteractive]]
    -formatZK    格式化Zookeeper实例
    -force: 如果znode存在,则格式化znode。 
    -nonInteractive:如果znode存在,则格式化znode中止,除非指定了-force选项
    -h    Display help

    23、verifyMeta 

    verifyMeta  #验证HDFS元数据和块文件。 如果指定了块文件,我们将验证元数据文件中的校验和是否与块文件匹配
    Usage: hdfs debug verifyMeta -meta <metadata-file> [-block <block-file>]
    -block block-file    用于指定数据节点的本地文件系统上的块文件的绝对路径
    -meta metadata-file    数据节点的本地文件系统上的元数据文件的绝对路径

    24、computeMeta

    computeMeta #从块文件计算HDFS元数据。 如果指定了块文件,我们将从块文件计算校验和,并将其保存到指定的输出元数据文件中
    Usage: hdfs debug computeMeta -block <block-file> -out <output-metadata-file>
    -block block-file    数据节点的本地文件系统上的块文件的绝对路径
    -out output-metadata-file    输出元数据文件的绝对路径,用于存储块文件的校验和计算结果。

    25、recoverLease

    recoverLease #恢复指定路径上的租约。 该路径必须驻留在HDFS文件系统上。 默认重试次数为1
    Usage: hdfs debug recoverLease -path <path> [-retries <num-retries>]
    [-path path]    要恢复租约的HDFS路径
    [-retries num-retries]    客户端重试调用recoverLease的次数。 默认重试次数为1

    更多hadoop生态文章请见:hadoop生态系列

  • 相关阅读:
    LA 2038 Strategic game(最小点覆盖,树形dp,二分匹配)
    UVA 10564 Paths through the Hourglass(背包)
    Codeforces Round #323 (Div. 2) D 582B Once Again...(快速幂)
    UVALive 3530 Martian Mining(贪心,dp)
    UVALive 4727 Jump(约瑟夫环,递推)
    UVALive 4731 Cellular Network(贪心,dp)
    UVA Mega Man's Mission(状压dp)
    Aizu 2456 Usoperanto (贪心)
    UVA 11404 Plalidromic Subsquence (回文子序列,LCS)
    Aizu 2304 Reverse Roads(无向流)
  • 原文地址:https://www.cnblogs.com/zsql/p/11580704.html
Copyright © 2011-2022 走看看