zoukankan      html  css  js  c++  java
  • Hadoop基础(八): HDFS客户端操作(一) HDFS客户端环境准备

    一、下载Hadoop jar包至非中文路径

    1. 下载链接:https://hadoop.apache.org/releases.html

    2. 解压至非中文路径
      在这里插入图片描述

    二、配置Hadoop环境变量

      1. 配置HADOOP_HOME环境变量
        在这里插入图片描述
      2. 配置Path环境变量
        在这里插入图片描述

    三、创建一个Maven工程

    1. 创建一个名为HdfsClientDemoMaven工程

    2. pom.xml中导入相应的依赖

    <dependencies>
            <dependency>
                <groupId>junit</groupId>
                <artifactId>junit</artifactId>
                <version>RELEASE</version>
            </dependency>
            <dependency>
                <groupId>org.apache.logging.log4j</groupId>
                <artifactId>log4j-core</artifactId>
                <version>2.8.2</version>
            </dependency>
            <dependency>
                <groupId>org.apache.hadoop</groupId>
                <artifactId>hadoop-common</artifactId>
                <version>2.7.2</version>
            </dependency>
            <dependency>
                <groupId>org.apache.hadoop</groupId>
                <artifactId>hadoop-client</artifactId>
                <version>2.7.2</version>
            </dependency>
            <dependency>
                <groupId>org.apache.hadoop</groupId>
                <artifactId>hadoop-hdfs</artifactId>
                <version>2.7.2</version>
            </dependency>
            <dependency>
                <groupId>jdk.tools</groupId>
                <artifactId>jdk.tools</artifactId>
                <version>1.8</version>
                <scope>system</scope>
                <systemPath>${JAVA_HOME}/lib/tools.jar</systemPath>
            </dependency>
    </dependencies>

    在项目的src/main/resources目录下,新建一个文件,命名为log4j.properties,在文件中填入

    log4j.rootLogger=INFO, stdout

    log4j.appender.stdout=org.apache.log4j.ConsoleAppender

    log4j.appender.stdout.layout=org.apache.log4j.PatternLayout

    log4j.appender.stdout.layout.ConversionPattern=%d %p [%c] - %m%n

    log4j.appender.logfile=org.apache.log4j.FileAppender

    log4j.appender.logfile.File=target/spring.log

    log4j.appender.logfile.layout=org.apache.log4j.PatternLayout

    log4j.appender.logfile.layout.ConversionPattern=%d %p [%c] - %m%n

    4 创建包名com.atguigu.hdfs

     5 创建HdfsClient

    public class HdfsClient{    
    @Test
    public void testMkdirs() throws IOException, InterruptedException, URISyntaxException{
            
            // 1 获取文件系统
            Configuration configuration = new Configuration();
            // 配置在集群上运行
            // configuration.set("fs.defaultFS", "hdfs://hadoop102:9000");
            // FileSystem fs = FileSystem.get(configuration);
    
            FileSystem fs = FileSystem.get(new URI("hdfs://hadoop102:9000"), configuration, "atguigu");
            
            // 2 创建目录
            fs.mkdirs(new Path("/1108/daxian/banzhang"));
            
            // 3 关闭资源
            fs.close();
        }
    }

    6 执行程序

  • 相关阅读:
    What is a .Net Assembly?
    Reading Assembly attributes in VB.NET
    Debugging With Visual Studio 2005
    The Rules for GetHashCode
    The article discusses a couple of new features introduced for assemblies and versioning in Visual Studio 2005.
    Getting a copy of a DLL in the GAC
    Modeling SingleNeuron Dynamics and Computations: A Balance of Detail and Abstraction
    从数学到密码学(八)
    从数学到密码学(十)
    从数学到密码学(三)
  • 原文地址:https://www.cnblogs.com/qiu-hua/p/13285628.html
Copyright © 2011-2022 走看看