zoukankan      html  css  js  c++  java
  • 大数据学习(2)HDFS文件管理

     命令行管理HDFS

    [root@server1 bin]# hadoop fs 
    Usage: hadoop fs [generic options]
            [-appendToFile <localsrc> ... <dst>]
            [-cat [-ignoreCrc] <src> ...]
            [-checksum <src> ...]
            [-chgrp [-R] GROUP PATH...]
            [-chmod [-R] <MODE[,MODE]... | OCTALMODE> PATH...]
            [-chown [-R] [OWNER][:[GROUP]] PATH...]
            [-copyFromLocal [-f] [-p] [-l] <localsrc> ... <dst>]
            [-copyToLocal [-p] [-ignoreCrc] [-crc] <src> ... <localdst>]
            [-count [-q] [-h] <path> ...]
            [-cp [-f] [-p | -p[topax]] <src> ... <dst>]
            [-createSnapshot <snapshotDir> [<snapshotName>]]
            [-deleteSnapshot <snapshotDir> <snapshotName>]
            [-df [-h] [<path> ...]]
            [-du [-s] [-h] <path> ...]
            [-expunge]
            [-get [-p] [-ignoreCrc] [-crc] <src> ... <localdst>]
            [-getfacl [-R] <path>]
            [-getfattr [-R] {-n name | -d} [-e en] <path>]
            [-getmerge [-nl] <src> <localdst>]
            [-help [cmd ...]]
            [-ls [-d] [-h] [-R] [<path> ...]]
            [-mkdir [-p] <path> ...]
            [-moveFromLocal <localsrc> ... <dst>]
            [-moveToLocal <src> <localdst>]
            [-mv <src> ... <dst>]
            [-put [-f] [-p] [-l] <localsrc> ... <dst>]
            [-renameSnapshot <snapshotDir> <oldName> <newName>]
            [-rm [-f] [-r|-R] [-skipTrash] <src> ...]
            [-rmdir [--ignore-fail-on-non-empty] <dir> ...]
            [-setfacl [-R] [{-b|-k} {-m|-x <acl_spec>} <path>]|[--set <acl_spec> <path>]]
            [-setfattr {-n name [-v value] | -x name} <path>]
            [-setrep [-R] [-w] <rep> <path> ...]
            [-stat [format] <path> ...]
            [-tail [-f] <file>]
            [-test -[defsz] <path>]
            [-text [-ignoreCrc] <src> ...]
            [-touchz <path> ...]
            [-usage [cmd ...]]

    JAVA操作HDFS

    maven依赖:

      <dependency>
            <groupId>jdk.tools</groupId>
            <artifactId>jdk.tools</artifactId>
            <version>1.6</version>
            <scope>system</scope>
            <systemPath>${JAVA_HOME}/lib/tools.jar</systemPath>
        </dependency>
        <dependency>
            <groupId>org.apache.hadoop</groupId>
            <artifactId>hadoop-hdfs</artifactId>
            <version>2.6.5</version>
        </dependency>
            
        <dependency>
            <groupId>org.apache.hadoop</groupId>
            <artifactId>hadoop-common</artifactId>
            <version>2.6.5</version>
        </dependency>

     上传&下载示例:

        public static void upload() throws Exception {
             Configuration conf = new Configuration();
             FileSystem fileSystem = FileSystem.get(new URI("hdfs://192.168.1.110:9000"),conf,"root");
             fileSystem.copyFromLocalFile(new Path("D:\test\2.txt"), new Path("/2.txt"));
             fileSystem.close();
        }
        public static void download() throws Exception {
            Configuration conf = new Configuration();
            conf.set("fs.defaultFS", "hdfs://192.168.1.110:9000");
            FileSystem fileSystem = FileSystem.get(conf);
            fileSystem.copyToLocalFile(false,new Path("/2.txt"),new Path("D:\test\2.download.txt"),true);
            fileSystem.close();
        }

    参考:

    HDFS文件管理:http://hadoop.apache.org/docs/r2.6.5/hadoop-project-dist/hadoop-hdfs/HDFSCommands.html

    API文档:https://hadoop.apache.org/docs/r2.8.2/api/index.html

  • 相关阅读:
    插件开发遇到的坑------final 型变量,编译过程被优化
    java.lang.NoClassDefFoundError 错误解决思路
    Android stadio bug
    android去掉button默认的点击阴影
    Andrid 打印调用堆栈
    Gradle 设置本地meaven
    Android log 里面快速搜索错误堆栈 ( 关键字)
    java doc 编写
    android 怎么判断activity 从哪里启动的
    Android Stadio调试gradle 插件 || Android Stadio 远程调试 || Anroid APT调试
  • 原文地址:https://www.cnblogs.com/at0x7c00/p/8045357.html
Copyright © 2011-2022 走看看