day_03小笔记----HDFS的API操作

5 篇文章 0 订阅

HDFS的API操作

1.准备工作:

启动集群:start-all.sh

登录http://hdp-1:50070/

2.在idea里从hdfs下载文件到本地磁盘

package com.zpark.hdfs;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.junit.Test;


import java.io.File;
import java.io.IOException;
import java.net.URI;

public class HdfsClient {

    //如果这个上传成功了,说明hadoop环境配置成功
    //    首先申请获得资源
   //   URI 统一资源标志符
   @Test
    public void put()throws IOException,InterruptedException{


//       FileSystem fileSystem =FileSystem.get(URI.create("hdfs://hdp-1:9000"),new Configuration(),"root");
//        fileSystem.copyFromLocalFile(new Path("d:\\1.txt"),new Path("/"));
//        fileSystem.close();


//       1.获取一个hdfs的抽象封装对象
          Configuration configuration = new Configuration();
       FileSystem fileSystem = FileSystem.get(URI.create("hdfs://hdp-1:9000"), configuration, "root");

//       2.用这个对象操作文件系统
       fileSystem.copyToLocalFile(new Path("/1.txt"),new Path("d:\\"));

//      3.关闭资源类
       fileSystem.close();
   }
};

2.修改hdfs文件名称

@Test
    public void rename()throws IOException,InterruptedException{
       //获取一个抽象封装对象
       Configuration configuration = new Configuration();
       FileSystem fileSystem = FileSystem.get(URI.create("hdfs://hdp-1:9000"), configuration, "root");

       //操作
       fileSystem.rename(new Path("/1.txt"),new Path("/2.txt"));
       //关闭
       fileSystem.close();
   }

3.删除hdfs上的文件

 @Test
    public void delete()throws IOException{
        boolean delete = fs.delete(new Path("/2.txt"),true);
        if(delete){
            System.out.println("删除成功");
        }else{
            System.out.println("删除失败");
        }

4.合并hdfs上的文件到某一指定位置

 @Test
    public void du()throws IOException{
        FSDataOutputStream append = fs.append(new Path("/2.txt"), 1024);
       FileInputStream open = new FileInputStream("d:\\1.txt");
        IOUtils.copyBytes(open,append,1024,true);
    }

5.查看hdfs上的文件信息---只查看文件夹

 @Test
   public void ls()throws IOException{
       FileStatus[] fileStatuses =fs.listStatus(new Path("/"));

       for (FileStatus fileStatus: fileStatuses) {
           if (fileStatus.isFile()){
               System.out.println("一下信息是一个文件的信息");
               System.out.println(fileStatus.getPath());
               System.out.println(fileStatus.getLen());
           }else{
               System.out.println("这是一个文件夹");
               System.out.println(fileStatus.getPath());
           }
       }

6.查看hdfs上的文件详细信息----只查看文件信息

@Test
public void listFiles()throws IOException{
    RemoteIterator<LocatedFileStatus> files =fs.listFiles(new Path("/"),true);

    while (files.hasNext()){
        LocatedFileStatus file =files.next();
        System.out.println("=================================");

        BlockLocation[] blockLocations =file.getBlockLocations();
        System.out.println(file.getPath());

        System.out.println("块信息");
        BlockLocation[]blockLocations1=file.getBlockLocations();
        for (BlockLocation blockLocation:blockLocations){
            String[] hosts =blockLocation.getHosts();
            System.out.println("块在");
            for (String host :hosts){
                System.out.println(host + " ");

            }
        }
    }
}

结果:

"C:\Program Files\Java\jdk1.8.0_144\bin\java.exe" -ea -Didea.test.cyclic.buffer.size=1048576 "-javaagent:F:\idea2019\2019.1.3idea\IntelliJ IDEA 2019.1.3\lib\idea_rt.jar=65141:F:\idea2019\2019.1.3idea\IntelliJ IDEA 2019.1.3\bin" -Dfile.encoding=UTF-8 -classpath "F:\idea2019\2019.1.3idea\IntelliJ IDEA 2019.1.3\lib\idea_rt.jar;F:\idea2019\2019.1.3idea\IntelliJ IDEA 2019.1.3\plugins\junit\lib\junit-rt.jar;F:\idea2019\2019.1.3idea\IntelliJ IDEA 2019.1.3\plugins\junit\lib\junit5-rt.jar;C:\Program Files\Java\jdk1.8.0_144\jre\lib\charsets.jar;C:\Program Files\Java\jdk1.8.0_144\jre\lib\deploy.jar;C:\Program Files\Java\jdk1.8.0_144\jre\lib\ext\access-bridge-64.jar;C:\Program Files\Java\jdk1.8.0_144\jre\lib\ext\cldrdata.jar;C:\Program Files\Java\jdk1.8.0_144\jre\lib\ext\dnsns.jar;C:\Program Files\Java\jdk1.8.0_144\jre\lib\ext\jaccess.jar;C:\Program Files\Java\jdk1.8.0_144\jre\lib\ext\jfxrt.jar;C:\Program Files\Java\jdk1.8.0_144\jre\lib\ext\localedata.jar;C:\Program Files\Java\jdk1.8.0_144\jre\lib\ext\nashorn.jar;C:\Program Files\Java\jdk1.8.0_144\jre\lib\ext\sunec.jar;C:\Program Files\Java\jdk1.8.0_144\jre\lib\ext\sunjce_provider.jar;C:\Program Files\Java\jdk1.8.0_144\jre\lib\ext\sunmscapi.jar;C:\Program Files\Java\jdk1.8.0_144\jre\lib\ext\sunpkcs11.jar;C:\Program Files\Java\jdk1.8.0_144\jre\lib\ext\zipfs.jar;C:\Program Files\Java\jdk1.8.0_144\jre\lib\javaws.jar;C:\Program Files\Java\jdk1.8.0_144\jre\lib\jce.jar;C:\Program Files\Java\jdk1.8.0_144\jre\lib\jfr.jar;C:\Program Files\Java\jdk1.8.0_144\jre\lib\jfxswt.jar;C:\Program Files\Java\jdk1.8.0_144\jre\lib\jsse.jar;C:\Program Files\Java\jdk1.8.0_144\jre\lib\management-agent.jar;C:\Program Files\Java\jdk1.8.0_144\jre\lib\plugin.jar;C:\Program Files\Java\jdk1.8.0_144\jre\lib\resources.jar;C:\Program Files\Java\jdk1.8.0_144\jre\lib\rt.jar;F:\idea2019\项目\target\classes;C:\Users\ABU\.m2\repository\junit\junit\4.13\junit-4.13.jar;C:\Users\ABU\.m2\repository\org\hamcrest\hamcrest-core\1.3\hamcrest-core-1.3.jar;C:\Users\ABU\.m2\repository\org\apache\logging\log4j\log4j-core\2.8.2\log4j-core-2.8.2.jar;C:\Users\ABU\.m2\repository\org\apache\logging\log4j\log4j-api\2.8.2\log4j-api-2.8.2.jar;C:\Users\ABU\.m2\repository\org\apache\hadoop\hadoop-common\2.8.1\hadoop-common-2.8.1.jar;C:\Users\ABU\.m2\repository\org\apache\hadoop\hadoop-annotations\2.8.1\hadoop-annotations-2.8.1.jar;C:\Users\ABU\.m2\repository\com\google\guava\guava\11.0.2\guava-11.0.2.jar;C:\Users\ABU\.m2\repository\commons-cli\commons-cli\1.2\commons-cli-1.2.jar;C:\Users\ABU\.m2\repository\org\apache\commons\commons-math3\3.1.1\commons-math3-3.1.1.jar;C:\Users\ABU\.m2\repository\xmlenc\xmlenc\0.52\xmlenc-0.52.jar;C:\Users\ABU\.m2\repository\org\apache\httpcomponents\httpclient\4.5.2\httpclient-4.5.2.jar;C:\Users\ABU\.m2\repository\org\apache\httpcomponents\httpcore\4.4.4\httpcore-4.4.4.jar;C:\Users\ABU\.m2\repository\commons-codec\commons-codec\1.4\commons-codec-1.4.jar;C:\Users\ABU\.m2\repository\commons-io\commons-io\2.4\commons-io-2.4.jar;C:\Users\ABU\.m2\repository\commons-net\commons-net\3.1\commons-net-3.1.jar;C:\Users\ABU\.m2\repository\commons-collections\commons-collections\3.2.2\commons-collections-3.2.2.jar;C:\Users\ABU\.m2\repository\javax\servlet\servlet-api\2.5\servlet-api-2.5.jar;C:\Users\ABU\.m2\repository\org\mortbay\jetty\jetty\6.1.26\jetty-6.1.26.jar;C:\Users\ABU\.m2\repository\org\mortbay\jetty\jetty-util\6.1.26\jetty-util-6.1.26.jar;C:\Users\ABU\.m2\repository\org\mortbay\jetty\jetty-sslengine\6.1.26\jetty-sslengine-6.1.26.jar;C:\Users\ABU\.m2\repository\javax\servlet\jsp\jsp-api\2.1\jsp-api-2.1.jar;C:\Users\ABU\.m2\repository\com\sun\jersey\jersey-core\1.9\jersey-core-1.9.jar;C:\Users\ABU\.m2\repository\com\sun\jersey\jersey-json\1.9\jersey-json-1.9.jar;C:\Users\ABU\.m2\repository\org\codehaus\jettison\jettison\1.1\jettison-1.1.jar;C:\Users\ABU\.m2\repository\com\sun\xml\bind\jaxb-impl\2.2.3-1\jaxb-impl-2.2.3-1.jar;C:\Users\ABU\.m2\repository\javax\xml\bind\jaxb-api\2.2.2\jaxb-api-2.2.2.jar;C:\Users\ABU\.m2\repository\javax\xml\stream\stax-api\1.0-2\stax-api-1.0-2.jar;C:\Users\ABU\.m2\repository\javax\activation\activation\1.1\activation-1.1.jar;C:\Users\ABU\.m2\repository\org\codehaus\jackson\jackson-jaxrs\1.8.3\jackson-jaxrs-1.8.3.jar;C:\Users\ABU\.m2\repository\org\codehaus\jackson\jackson-xc\1.8.3\jackson-xc-1.8.3.jar;C:\Users\ABU\.m2\repository\com\sun\jersey\jersey-server\1.9\jersey-server-1.9.jar;C:\Users\ABU\.m2\repository\asm\asm\3.1\asm-3.1.jar;C:\Users\ABU\.m2\repository\commons-logging\commons-logging\1.1.3\commons-logging-1.1.3.jar;C:\Users\ABU\.m2\repository\log4j\log4j\1.2.17\log4j-1.2.17.jar;C:\Users\ABU\.m2\repository\net\java\dev\jets3t\jets3t\0.9.0\jets3t-0.9.0.jar;C:\Users\ABU\.m2\repository\com\jamesmurty\utils\java-xmlbuilder\0.4\java-xmlbuilder-0.4.jar;C:\Users\ABU\.m2\repository\commons-lang\commons-lang\2.6\commons-lang-2.6.jar;C:\Users\ABU\.m2\repository\commons-configuration\commons-configuration\1.6\commons-configuration-1.6.jar;C:\Users\ABU\.m2\repository\commons-digester\commons-digester\1.8\commons-digester-1.8.jar;C:\Users\ABU\.m2\repository\commons-beanutils\commons-beanutils\1.7.0\commons-beanutils-1.7.0.jar;C:\Users\ABU\.m2\repository\commons-beanutils\commons-beanutils-core\1.8.0\commons-beanutils-core-1.8.0.jar;C:\Users\ABU\.m2\repository\org\slf4j\slf4j-api\1.7.10\slf4j-api-1.7.10.jar;C:\Users\ABU\.m2\repository\org\slf4j\slf4j-log4j12\1.7.10\slf4j-log4j12-1.7.10.jar;C:\Users\ABU\.m2\repository\org\codehaus\jackson\jackson-core-asl\1.9.13\jackson-core-asl-1.9.13.jar;C:\Users\ABU\.m2\repository\org\codehaus\jackson\jackson-mapper-asl\1.9.13\jackson-mapper-asl-1.9.13.jar;C:\Users\ABU\.m2\repository\org\apache\avro\avro\1.7.4\avro-1.7.4.jar;C:\Users\ABU\.m2\repository\com\thoughtworks\paranamer\paranamer\2.3\paranamer-2.3.jar;C:\Users\ABU\.m2\repository\org\xerial\snappy\snappy-java\1.0.4.1\snappy-java-1.0.4.1.jar;C:\Users\ABU\.m2\repository\com\google\protobuf\protobuf-java\2.5.0\protobuf-java-2.5.0.jar;C:\Users\ABU\.m2\repository\com\google\code\gson\gson\2.2.4\gson-2.2.4.jar;C:\Users\ABU\.m2\repository\org\apache\hadoop\hadoop-auth\2.8.1\hadoop-auth-2.8.1.jar;C:\Users\ABU\.m2\repository\com\nimbusds\nimbus-jose-jwt\3.9\nimbus-jose-jwt-3.9.jar;C:\Users\ABU\.m2\repository\net\jcip\jcip-annotations\1.0\jcip-annotations-1.0.jar;C:\Users\ABU\.m2\repository\net\minidev\json-smart\1.1.1\json-smart-1.1.1.jar;C:\Users\ABU\.m2\repository\org\apache\directory\server\apacheds-kerberos-codec\2.0.0-M15\apacheds-kerberos-codec-2.0.0-M15.jar;C:\Users\ABU\.m2\repository\org\apache\directory\server\apacheds-i18n\2.0.0-M15\apacheds-i18n-2.0.0-M15.jar;C:\Users\ABU\.m2\repository\org\apache\directory\api\api-asn1-api\1.0.0-M20\api-asn1-api-1.0.0-M20.jar;C:\Users\ABU\.m2\repository\org\apache\directory\api\api-util\1.0.0-M20\api-util-1.0.0-M20.jar;C:\Users\ABU\.m2\repository\org\apache\curator\curator-framework\2.7.1\curator-framework-2.7.1.jar;C:\Users\ABU\.m2\repository\com\jcraft\jsch\0.1.51\jsch-0.1.51.jar;C:\Users\ABU\.m2\repository\org\apache\curator\curator-client\2.7.1\curator-client-2.7.1.jar;C:\Users\ABU\.m2\repository\org\apache\curator\curator-recipes\2.7.1\curator-recipes-2.7.1.jar;C:\Users\ABU\.m2\repository\com\google\code\findbugs\jsr305\3.0.0\jsr305-3.0.0.jar;C:\Users\ABU\.m2\repository\org\apache\htrace\htrace-core4\4.0.1-incubating\htrace-core4-4.0.1-incubating.jar;C:\Users\ABU\.m2\repository\org\apache\zookeeper\zookeeper\3.4.6\zookeeper-3.4.6.jar;C:\Users\ABU\.m2\repository\org\apache\commons\commons-compress\1.4.1\commons-compress-1.4.1.jar;C:\Users\ABU\.m2\repository\org\tukaani\xz\1.0\xz-1.0.jar;C:\Users\ABU\.m2\repository\org\apache\hadoop\hadoop-client\2.8.1\hadoop-client-2.8.1.jar;C:\Users\ABU\.m2\repository\org\apache\hadoop\hadoop-mapreduce-client-app\2.8.1\hadoop-mapreduce-client-app-2.8.1.jar;C:\Users\ABU\.m2\repository\org\apache\hadoop\hadoop-mapreduce-client-common\2.8.1\hadoop-mapreduce-client-common-2.8.1.jar;C:\Users\ABU\.m2\repository\org\apache\hadoop\hadoop-yarn-client\2.8.1\hadoop-yarn-client-2.8.1.jar;C:\Users\ABU\.m2\repository\org\apache\hadoop\hadoop-yarn-server-common\2.8.1\hadoop-yarn-server-common-2.8.1.jar;C:\Users\ABU\.m2\repository\org\apache\hadoop\hadoop-mapreduce-client-shuffle\2.8.1\hadoop-mapreduce-client-shuffle-2.8.1.jar;C:\Users\ABU\.m2\repository\org\apache\hadoop\hadoop-yarn-api\2.8.1\hadoop-yarn-api-2.8.1.jar;C:\Users\ABU\.m2\repository\org\apache\hadoop\hadoop-mapreduce-client-core\2.8.1\hadoop-mapreduce-client-core-2.8.1.jar;C:\Users\ABU\.m2\repository\org\apache\hadoop\hadoop-yarn-common\2.8.1\hadoop-yarn-common-2.8.1.jar;C:\Users\ABU\.m2\repository\com\sun\jersey\jersey-client\1.9\jersey-client-1.9.jar;C:\Users\ABU\.m2\repository\org\apache\hadoop\hadoop-mapreduce-client-jobclient\2.8.1\hadoop-mapreduce-client-jobclient-2.8.1.jar;C:\Users\ABU\.m2\repository\org\apache\hadoop\hadoop-hdfs\2.8.1\hadoop-hdfs-2.8.1.jar;C:\Users\ABU\.m2\repository\org\apache\hadoop\hadoop-hdfs-client\2.8.1\hadoop-hdfs-client-2.8.1.jar;C:\Users\ABU\.m2\repository\com\squareup\okhttp\okhttp\2.4.0\okhttp-2.4.0.jar;C:\Users\ABU\.m2\repository\com\squareup\okio\okio\1.4.0\okio-1.4.0.jar;C:\Users\ABU\.m2\repository\commons-daemon\commons-daemon\1.0.13\commons-daemon-1.0.13.jar;C:\Users\ABU\.m2\repository\io\netty\netty\3.6.2.Final\netty-3.6.2.Final.jar;C:\Users\ABU\.m2\repository\io\netty\netty-all\4.0.23.Final\netty-all-4.0.23.Final.jar;C:\Users\ABU\.m2\repository\xerces\xercesImpl\2.9.1\xercesImpl-2.9.1.jar;C:\Users\ABU\.m2\repository\xml-apis\xml-apis\1.3.04\xml-apis-1.3.04.jar;C:\Users\ABU\.m2\repository\org\fusesource\leveldbjni\leveldbjni-all\1.8\leveldbjni-all-1.8.jar;C:\Program Files\Java\jdk1.8.0_144\lib\tools.jar" com.intellij.rt.execution.junit.JUnitStarter -ideVersion5 -junit4 com.zpark.hdfs.HdfsClient,listFiles
2020-01-29 17:20:24,849 WARN [org.apache.hadoop.util.NativeCodeLoader] - Unable to load native-hadoop library for your platform... using builtin-java classes where applicable
Before!!!
=================================
hdfs://hdp-1:9000/1.txt
块信息
块在
hdp-1 
hdp-3 
hdp-4 
=================================
hdfs://hdp-1:9000/2.txt
块信息
块在
hdp-1 
hdp-3 
hdp-4 
=================================
hdfs://hdp-1:9000/access/log/tmp.hh
块信息
块在
hdp-3 
hdp-4 
=================================
hdfs://hdp-1:9000/access/log/tmp_copy_1.hh
块信息
块在
hdp-3 
hdp-1 
=================================
hdfs://hdp-1:9000/hbase/MasterProcWALs/state-00000000000000000003.log
块信息
块在
hdp-3 
hdp-1 
hdp-4 
=================================
hdfs://hdp-1:9000/hbase/MasterProcWALs/state-00000000000000000004.log
块信息
块在
hdp-3 
hdp-1 
=================================
hdfs://hdp-1:9000/hbase/data/hbase/meta/.tabledesc/.tableinfo.0000000001
块信息
块在
hdp-3 
hdp-1 
hdp-4 
=================================
hdfs://hdp-1:9000/hbase/data/hbase/meta/1588230740/.regioninfo
块信息
块在
hdp-3 
hdp-1 
hdp-4 
=================================
hdfs://hdp-1:9000/hbase/data/hbase/meta/1588230740/info/ec500618a63a40859b90a41a377da9b3
块信息
块在
hdp-3 
hdp-1 
hdp-4 
=================================
hdfs://hdp-1:9000/hbase/data/hbase/meta/1588230740/info/f77d64441ac64ebeb88bea706f19470f
块信息
块在
hdp-3 
hdp-1 
hdp-4 
=================================
hdfs://hdp-1:9000/hbase/data/hbase/meta/1588230740/recovered.edits/19.seqid
块信息
=================================
hdfs://hdp-1:9000/hbase/data/hbase/namespace/.tabledesc/.tableinfo.0000000001
块信息
块在
hdp-3 
hdp-1 
hdp-4 
=================================
hdfs://hdp-1:9000/hbase/data/hbase/namespace/93e82fb80e464a297796342e7452d786/.regioninfo
块信息
块在
hdp-3 
hdp-1 
hdp-4 
=================================
hdfs://hdp-1:9000/hbase/data/hbase/namespace/93e82fb80e464a297796342e7452d786/info/e85c4af4c5ff46b899260defc79f5bd3
块信息
块在
hdp-3 
hdp-1 
hdp-4 
=================================
hdfs://hdp-1:9000/hbase/data/hbase/namespace/93e82fb80e464a297796342e7452d786/recovered.edits/13.seqid
块信息
=================================
hdfs://hdp-1:9000/hbase/hbase.id
块信息
块在
hdp-3 
hdp-1 
hdp-4 
=================================
hdfs://hdp-1:9000/hbase/hbase.version
块信息
块在
hdp-3 
hdp-1 
hdp-4 
=================================
hdfs://hdp-1:9000/hbase/oldWALs/hdp-1%2C16020%2C1560237443057.default.1560237454571
块信息
块在
hdp-3 
hdp-1 
hdp-4 
=================================
hdfs://hdp-1:9000/hbase/oldWALs/hdp-2%2C16020%2C1560237435943.default.1560237454470
块信息
块在
hdp-3 
hdp-1 
hdp-4 
=================================
hdfs://hdp-1:9000/hbase/oldWALs/hdp-3%2C16020%2C1560237436343..meta.1560237455807.meta
块信息
块在
hdp-3 
hdp-1 
hdp-4 
=================================
hdfs://hdp-1:9000/hbase/oldWALs/hdp-3%2C16020%2C1560237436343.default.1560237454292
块信息
块在
hdp-3 
hdp-1 
hdp-4 
=================================
hdfs://hdp-1:9000/mapreduce/wordcount/input/hello.txt
块信息
块在
hdp-3 
hdp-4 
=================================
hdfs://hdp-1:9000/mapreduce/wordcount/output/_SUCCESS
块信息
=================================
hdfs://hdp-1:9000/mapreduce/wordcount/output/part-r-00000
块信息
块在
hdp-3 
hdp-4 
=================================
hdfs://hdp-1:9000/output/flume.listen.frame.access.log/2019-10-15-01-11-38.1571073098359
块信息
块在
hdp-3 
hdp-1 
=================================
hdfs://hdp-1:9000/output/flume.listen.frame.access.log/2019-10-15-01-11-41.1571073101730
块信息
块在
hdp-3 
hdp-1 
=================================
hdfs://hdp-1:9000/tmp/hadoop-yarn/staging/history/done_intermediate/root/job_1571621838114_0001-1571651568280-root-select+count%28*%29+from+t_access%28Stage%2D1%29-1571651665221-1-1-SUCCEEDED-default-1571651621593.jhist
块信息
块在
hdp-3 
hdp-1 
=================================
hdfs://hdp-1:9000/tmp/hadoop-yarn/staging/history/done_intermediate/root/job_1571621838114_0001.summary
块信息
块在
hdp-3 
hdp-1 
=================================
hdfs://hdp-1:9000/tmp/hadoop-yarn/staging/history/done_intermediate/root/job_1571621838114_0001_conf.xml
块信息
块在
hdp-3 
hdp-1 
=================================
hdfs://hdp-1:9000/tmp/hadoop-yarn/staging/history/done_intermediate/root/job_1571621838114_0002-1571651663726-root-select+count%28*%29+from+t_access%28Stage%2D1%29-1571651741895-1-1-SUCCEEDED-default-1571651710107.jhist
块信息
块在
hdp-3 
hdp-1 
=================================
hdfs://hdp-1:9000/tmp/hadoop-yarn/staging/history/done_intermediate/root/job_1571621838114_0002.summary
块信息
块在
hdp-3 
hdp-1 
=================================
hdfs://hdp-1:9000/tmp/hadoop-yarn/staging/history/done_intermediate/root/job_1571621838114_0002_conf.xml
块信息
块在
hdp-3 
hdp-1 
=================================
hdfs://hdp-1:9000/tmp/hadoop-yarn/staging/history/done_intermediate/root/job_1571705889780_0001-1571708232521-root-select+count%28*%29+from+t_access%28Stage%2D1%29-1571708272305-1-1-SUCCEEDED-default-1571708247400.jhist
块信息
块在
hdp-3 
hdp-1 
=================================
hdfs://hdp-1:9000/tmp/hadoop-yarn/staging/history/done_intermediate/root/job_1571705889780_0001.summary
块信息
块在
hdp-3 
hdp-1 
=================================
hdfs://hdp-1:9000/tmp/hadoop-yarn/staging/history/done_intermediate/root/job_1571705889780_0001_conf.xml
块信息
块在
hdp-3 
hdp-1 
=================================
hdfs://hdp-1:9000/tmp/hadoop-yarn/staging/history/done_intermediate/root/job_1572315205036_0001-1572315500061-root-math%2D1.0%2DSNAPSHOT.jar-1572315555640-1-1-SUCCEEDED-default-1572315522708.jhist
块信息
块在
hdp-3 
hdp-1 
=================================
hdfs://hdp-1:9000/tmp/hadoop-yarn/staging/history/done_intermediate/root/job_1572315205036_0001.summary
块信息
块在
hdp-3 
hdp-4 
=================================
hdfs://hdp-1:9000/tmp/hadoop-yarn/staging/history/done_intermediate/root/job_1572315205036_0001_conf.xml
块信息
块在
hdp-3 
hdp-1 
=================================
hdfs://hdp-1:9000/tmp/hadoop-yarn/staging/history/done_intermediate/root/job_1572315205036_0002-1572316059449-root-wc.jar-1572316100574-1-1-SUCCEEDED-default-1572316072591.jhist
块信息
块在
hdp-3 
hdp-1 
=================================
hdfs://hdp-1:9000/tmp/hadoop-yarn/staging/history/done_intermediate/root/job_1572315205036_0002.summary
块信息
块在
hdp-3 
hdp-1 
=================================
hdfs://hdp-1:9000/tmp/hadoop-yarn/staging/history/done_intermediate/root/job_1572315205036_0002_conf.xml
块信息
块在
hdp-3 
hdp-4 
=================================
hdfs://hdp-1:9000/tmp/hadoop-yarn/staging/history/done_intermediate/root/job_1579329812705_0003-1579331614656-root-word+count-1579331650124-1-1-SUCCEEDED-default-1579331628313.jhist
块信息
块在
hdp-4 
hdp-3 
=================================
hdfs://hdp-1:9000/tmp/hadoop-yarn/staging/history/done_intermediate/root/job_1579329812705_0003.summary
块信息
块在
hdp-4 
hdp-3 
=================================
hdfs://hdp-1:9000/tmp/hadoop-yarn/staging/history/done_intermediate/root/job_1579329812705_0003_conf.xml
块信息
块在
hdp-4 
hdp-3 
=================================
hdfs://hdp-1:9000/user/root/wcinput/wc.input
块信息
块在
hdp-4 
hdp-3 
=================================
hdfs://hdp-1:9000/user/root/wcoutput/_SUCCESS
块信息
=================================
hdfs://hdp-1:9000/user/root/wcoutput/part-r-00000
块信息
块在
hdp-3 
hdp-4 
=================================
hdfs://hdp-1:9000/wcinput/wc.input
块信息
块在
hdp-3 
hdp-1 
After

Process finished with exit code 0

7.查看hdfs上设置备份

@Test
    public void put1() throws IOException, InterruptedException {

        //设置配置文件
        Configuration configuration = new Configuration();
//        configuration.setInt("dfs.replication",1);


        fs = FileSystem.get(URI.create("hdfs://hdp-1:9000"), configuration, "root");
        fs.copyFromLocalFile(new Path("d:/1.txt"), new Path("/3.txt"));
    }

如果没有设置备份数,按照默认备份数算

(在resources--》hdfs-site.xml)

<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
<!--
  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License. See accompanying LICENSE file.
-->

<!-- Put site-specific property overrides in this file. -->

<configuration>
    <!-- 指定HDFS副本的数量 -->
    <property>
        <name>dfs.replication</name>
        <value>2</value>
    </property>

</configuration>

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值