【@deprecated】Hadoop3,IDEA远程访问集群进行调试,Scala+Java混合开发

一、Hadoop3部分变化

标记下,找时间消化

1-1、擦除编码

https://hadoop.apache.org/docs/r3.0.3/hadoop-project-dist/hadoop-hdfs/HDFSErasureCoding.html

1-2、Hadoop 3 端口号的改变

在这里插入图片描述

1-3、支持2个以上的NameNode

https://hadoop.apache.org/docs/r3.0.3/hadoop-project-dist/hadoop-hdfs/HDFSHighAvailabilityWithQJM.html

1-4、内部数据节点平衡器

添加或替换磁盘可能会导致DataNode中的数据倾斜,See the disk balancer section in the HDFS Commands Guide for more information

二、IDEA远程访问控制集群

2-1 创建Maven项目,添加hadoop-client依赖

问题:Dependency 'org.apache.hadoop:hadoop-client:3.0.0-cdh6.2.0' not found
解决:添加仓库

    <repositories>
        <repository>
            <id>cloudera</id>
            <url>https://repository.cloudera.com/artifactory/cloudera-repos/</url>
        </repository>
    </repositories>

2-2 加入集群上的配置文件,准备本地环境

  • 注意,配置文件中如果设置的是hostname,远程提交代码的机器,host中需要设置对应的ip
    补充:
    一直排斥在本地安装Hadoop环境,以前确实这样做过,行得通。但是一直难以理解。我为什么需要在本地也安装Hadoop(严格说不是安装,只是有相关文件),本地的又不会执行。
    但是事实证明,本地没有相关文件,会有很多操作执行不了,比如下载文件到本地。
    稍微可信一点的解释: 本地需要缓存一些东西
    Hadoop存档下载: https://archive.apache.org/dist/hadoop/core/
  • bin下放置winutils.exe: 各版本的Hadoop dll以及 winutils

2-3、查看文件/目录

    public static void ls(FileSystem fs, String path) throws IOException {
        FileStatus[] fileStatus = fs.listStatus(new Path(path));
        for(FileStatus status : fileStatus){
            System.out.println(status.getPath().toString());
        }
    }

2-4、创建目录

  • exists()总是返回true,暂未解决
    /**
     * TODO: 文件或目录存在的情况
     * @param fs
     * @param path
     * @return
     */
    public static boolean mkdir(FileSystem fs, String path) {
        Preconditions.checkNotNull(path);
        if (!isValidHdfsPath(path)) return false;
        try {
            fs.mkdirs(new Path(path));
            return true;
        } catch (IOException e) {
            e.printStackTrace();
            LOG.error(e.getMessage());
            return false;
        }
    }
    public static boolean isValidHdfsPath(String fileName) {
        return fileName.startsWith(HDFS_SCHEME);
    }

2-5、上传本地文件

    public static void localToHdfs(FileSystem fs, String srcFile, String destPath) throws IOException {
        fs.copyFromLocalFile(new Path(srcFile),new Path(HDFS_SCHEME + destPath));
    }

2-6、人生苦短,远离远程调试

还是在centos机器上直接开发吧

  • teamciewer
  • 向日葵
  • vncviewer

https://blog.csdn.net/changzehai/article/details/78826354
https://blog.csdn.net/tpaijojo/article/details/79115095

三、混合开发、完整pom文件

3-1、直接安装scala sdk(推荐,省事)

  1. 安装后直接解压,设置SCALA_HOME以及PATH
  2. 配置global libraries
    这种方式不用在maven中设置依赖以及编译插件
  3. 安装Scala插件(语法检查、高亮、格式化等特性),重启IDEA

3-2、 不安装scala sdk

  1. pom中引入scala相关库,配置scala相关的plugin
    2.安装Scala插件(语法检查、高亮、格式化等特性),重启IDEA
  2. 然后工程中main和test下自建相应的目录
  3. 创建scala文件
    没安装Scala SDk的情况下,至少需要:
    scala-library
    scala-maven-plugin

3-3、pom

在这里插入图片描述

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <repositories>
        <repository>
            <id>cloudera</id>
            <url>https://repository.cloudera.com/artifactory/cloudera-repos/</url>
        </repository>
    </repositories>

    <groupId>wh</groupId>
    <artifactId>env.test</artifactId>
    <version>1.0-SNAPSHOT</version>

    <properties>
        <scala.version>2.11.11</scala.version>
        <spark.version>2.4.0-cdh6.2.0</spark.version>
        <hadoop.version>3.0.0-cdh6.2.0</hadoop.version>

        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.scala-lang</groupId>
            <artifactId>scala-library</artifactId>
            <version>${scala.version}</version>
        </dependency>
        <dependency>
            <groupId>org.scala-lang</groupId>
            <artifactId>scala-compiler</artifactId>
            <version>${scala.version}</version>
        </dependency>
        <dependency>
            <groupId>org.scala-lang</groupId>
            <artifactId>scala-reflect</artifactId>
            <version>${scala.version}</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.apache.spark/spark-core -->
        <dependency>
            <groupId>org.apache.spark</groupId>
            <artifactId>spark-core_2.11</artifactId>
            <version>${spark.version}</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.apache.hadoop/hadoop-client -->
        <dependency>
            <groupId>org.apache.hadoop</groupId>
            <artifactId>hadoop-client</artifactId>
            <version>${hadoop.version}</version>
        </dependency>

    </dependencies>

    <build>
        <finalName>${project.artifactId}</finalName>
        <plugins>
            <!-- scala编译插件 -->
            <plugin>
                <groupId>net.alchim31.maven</groupId>
                <artifactId>scala-maven-plugin</artifactId>
                <version>4.0.1</version>
                <executions>
                    <execution>
                        <id>scala-compile-first</id>
                        <phase>process-resources</phase>
                        <goals>
                            <goal>add-source</goal>
                            <goal>compile</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>scala-test-compile</id>
                        <phase>process-test-resources</phase>
                        <goals>
                            <goal>testCompile</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <!-- java编译插件 -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.8.0</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                    <encoding>UTF-8</encoding>
                </configuration>
            </plugin>
            <!-- This plugin adds all dependencies to JAR file during 'package' command.
            Pay EXTRA attention to the 'mainClass' tag.
            You have to set name of class with entry point to program ('main' method) -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-assembly-plugin</artifactId>
                <version>3.1.0</version>
                <configuration>
                    <descriptorRefs>
                        <descriptorRef>jar-with-dependencies</descriptorRef>
                    </descriptorRefs>
                    <archive>
                        <manifest>
                            <mainClass>ScalaRunner</mainClass>
                        </manifest>
                    </archive>
                </configuration>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>single</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>

四、错误记录

  • 问题:Dependency 'org.apache.hadoop:hadoop-client:3.0.0-cdh6.2.0' not found
    解决:添加仓库
    <repositories>
        <repository>
            <id>cloudera</id>
            <url>https://repository.cloudera.com/artifactory/cloudera-repos/</url>
        </repository>
    </repositories>
  • 问题:HADOOP_HOME and hadoop.home.dir are unset
    解决: 本地Hadoop环境以及winutils.exe等,见2-2

  • 问题:Caused by: com.fasterxml.jackson.databind.JsonMappingException: Incompatible Jackson version: 2.9.8

提示jackson.databind版本与 jackson.module版本不匹配

解决:
起初为了省事,我把cdh下的jars都加进来了,起了些冲突。
在这里插入图片描述

  • 问题:[org.apache.hadoop.ipc.Client] Retrying connect to server: node6.com/some ip:8020. Already tried 6 time(s); maxRetries=45
    解决: 奇怪的是node6.com以及ip的值,我并没有设置过这些值
  1. netstat -an | grep 8020,发现多个TIME_WAIT,0.0.0.0:*正在监听8020端口
  2. 将信将疑注释了namenode的/etc/hosts/中的127.0.0.1

参考

  1. CDH 权限探索
  2. HDFS 客户端权限
  3. 各版本的Hadoop dll以及 winutils](https://github.com/steveloughran/winutils)
  4. Discover Intellij IDEA for Scala
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值