zoukankan      html  css  js  c++  java
  • win10-idea连接hdfs集群

    1、 创建maven项目

    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>

    如果jdk.tools依赖无法安装

      a. 可能是java_home存在空格,检查并更新路径

      b. 可以修改systempath 为绝对路径

    3、 启动集群,测试是否成功

      a.

        start-dfs.sh

        start-yarn.sh

      b. 

    public class HDFSClient {
        public static void main(String[] args) throws IOException {
            // 1 获取hdfs客户端对象
            Configuration conf = new Configuration();
            // 确定要访问的集群
            conf.set("fs.defaultFS","hdfs://hadoop102:9000");
            FileSystem fs = FileSystem.get(conf);
            // 2 在hdfs上创建路径
            fs.mkdirs(new Path("/1026/jenkindemo"));
            // 3 关闭资源
            fs.close();
            System.out.println("over");
        }
    }

      抛出异常

       解决方式

       

      在VMoption中输入:-DHADOOP_USER_NAME=linux的用户名

       

      第二种解决方式

      

    FileSystem fs = FileSystem.get(new URI("hdfs://hadoop102:9000"),conf,"jenkin");

      over 连接成功

  • 相关阅读:
    hdu 1895 Sum Zero hash
    hdu 4277 USACO ORZ dfs+hash
    hdu 6010 Daylight Saving Time 泰勒公式
    Codeforces Round #FF (Div. 2) D. DZY Loves Modification 优先队列
    Codeforces Round #113 (Div. 2) B. Polygons Andrew求凸包
    poj 3304 Segments 线段与直线相交
    gym 101081 gym F. Auction of Services 最小生成树+倍增LCA
    hdu 1558 Segment set 线段相交+并查集
    gym 101081 E. Polish Fortress 几何
    SPOJ
  • 原文地址:https://www.cnblogs.com/choice7/p/14281002.html
Copyright © 2011-2022 走看看