集群模式执行Spark程序(第七弹)

17 篇文章 0 订阅
17 篇文章 0 订阅

#添加打包插件

在pom.xml文件中添加所需插件

插入内容如下:

<build>

    <sourceDirectory>src/main/scala</sourceDirectory>

    <testSourceDirectory>src/test/scala</testSourceDirectory>

    <plugins>

        <plugin>

            <groupId>net.alchim31.maven</groupId>

            <artifactId>scala-maven-plugin</artifactId>

            <version>3.2.2</version>

            <executions>

                <execution>

                    <goals>

                        <goal>compile</goal>

                        <goal>testCompile</goal>

                    </goals>

                    <configuration>

                        <args>

                            <arg>-dependencyfile</arg>

                            <arg>${project.build.directory}/.scala_dependencies</arg>

                        </args>

                    </configuration>

                </execution>

            </executions>

        </plugin>

        <plugin>

            <groupId>org.apache.maven.plugins</groupId>

            <artifactId>maven-shade-plugin</artifactId>

            <version>2.4.3</version>

            <executions>

                <execution>

                    <phase>package</phase>

                    <goals>

                        <goal>shade</goal>

                    </goals>

                    <configuration>

                        <filters>

                            <filter>

                                <artifact>*:*</artifact>

                                <excludes>

                                    <exclude>META-INF/*.SF</exclude>

                                    <exclude>META-INF/*.DSA</exclude>

                                    <exclude>META-INF/*.RSA</exclude>

                                </excludes>

                            </filter>

                        </filters>

                        <transformers>

                            <transformer implementation=

                                                 "org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">

                                <mainClass></mainClass>

                            </transformer>

                        </transformers>

                    </configuration>

                </execution>

            </executions>

        </plugin>

    </plugins>

</build>

等待加载

步骤1 将鼠标点在WordCount ,ctrl+c后ctrl+v复制,重新命名为WordCount_Online

步骤2 修改代码

    # 3.读取数据文件,RDD可以简单的理解为是一个集合,集合中存放的元素是String类型

val data : RDD[String] = sparkContext.textFile(args(0))

# 7.把结果数据保存到HDFS上

result.saveAsTextFile(args(1))

# 修改以上这2行代码

步骤3 点击右边【maven projects】—>双击【lifecycle】下的package,自动将项目打包成Jar包

打包成功标志: 显示BUILD SUCCESS,可以看到target目录下的2个jar包

步骤4 启动Hadoop集群才能访问web页面

$ start-all.sh

步骤5 访问192.168.196.101(master):50070 点击【utilities】—>【browse the file system】

步骤6 点击【spark】—>【test】,可以看到words.txt

步骤7 将words.txt删除

$  hadoop fs -rm /spark/test/words.txt

步骤8 刷新下页面。可以看到/spark/test路径下没有words.txt

步骤9  Alt+p,切到/opt/software,把含有第3方jar的spark_chapter02-1.0-SNAPSHOT.jar包拉进

#先将解压的两个jar包复制出来

步骤10 也把F盘/word/words.txt直接拉进/opt/software

步骤11 查看有没有words.txt和spark_chapter02-1.0-SNAPSHOT.jar

步骤12 执行提交命令

$ bin/spark-submit \

 --master spark://master:7077 \

 --executor-memory 1g \

 --total-executor-cores 1 \

/opt/software/spark_chapter02-1.0-SNAPSHOT.jar \

/spark/test/words.txt \

/spark/test/out

  • 9
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 15
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 15
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

发量不足

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值