【问题标题】:Running Spark on Yarn Client在 Yarn 客户端上运行 Spark
【发布时间】:2016-07-23 19:35:46
【问题描述】:

我最近设置了一个多节点 Hadoop HA (Namenode & ResourceManager) Cluster (3 node),安装完成,所有守护进程都按预期运行

NN1 中的守护进程:

2945 JournalNode
3137 DFSZKFailoverController
6385 Jps
3338 NodeManager
22730 QuorumPeerMain
2747 DataNode
3228 ResourceManager
2636 NameNode

NN2 中的守护进程:

19620 Jps
3894 QuorumPeerMain
16966 ResourceManager
16808 NodeManager
16475 DataNode
16572 JournalNode
17101 NameNode
16702 DFSZKFailoverController

DN1 中的守护进程:

12228 QuorumPeerMain
29060 NodeManager
28858 DataNode
29644 Jps
28956 JournalNode

我有兴趣在我的 Yarn 设置上运行 Spark Jobs。 我已经在我的 NN1 上安装了 Scala 和 Spark,我可以通过发出以下命令成功启动我的 spark

$ spark-shell

现在,我对 SPARK 一无所知,我想知道如何在 Yarn 上运行 Spark。我读到我们可以将它作为 yarn-client 或 yarn-cluster 运行。

我应该在集群中的所有节点(NN2 和 DN1)上安装 spark 和 scala 以在 Yarn 客户端或集群上运行 spark 吗?如果否,那么我如何从 NN1(主名称节点)主机提交 Spark 作业。

按照我阅读的博客中的建议,我已将 Spark 程序集 JAR 复制到 HDFS,

-rw-r--r--   3 hduser supergroup  187548272 2016-04-04 15:56 /user/spark/share/lib/spark-assembly.jar

还在我的 bashrc 文件中创建了 SPARK_JAR 变量。我尝试将 Spark 作业作为 yarn-client 提交,但最终出现如下错误,我不知道我做的是否正确或需要其他设置首先完成。

[hduser@ptfhadoop01v spark-1.6.0]$ ./bin/spark-submit --class     org.apache.spark.examples.SparkPi --master yarn  --deploy-mode client --driver-memory 4g --executor-memory 2g --executor-cores 2 --queue thequeue lib/spark-examples*.jar 10
16/04/04 17:27:50 WARN NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable
16/04/04 17:27:51 WARN SparkConf:
SPARK_WORKER_INSTANCES was detected (set to '2').
This is deprecated in Spark 1.0+.

Please instead use:
 - ./spark-submit with --num-executors to specify the number of executors
 - Or set SPARK_EXECUTOR_INSTANCES
 - spark.executor.instances to configure the number of instances in the spark config.

16/04/04 17:27:54 WARN Client: SPARK_JAR detected in the system environment.  This variable has been deprecated in favor of the spark.yarn.jar configuration variable.
16/04/04 17:27:54 WARN Client: SPARK_JAR detected in the system environment.   This variable has been deprecated in favor of the spark.yarn.jar configuration variable.
16/04/04 17:27:57 ERROR SparkContext: Error initializing SparkContext.
org.apache.spark.SparkException: Yarn application has already ended! It might have been killed or unable to launch application master.
    at   org.apache.spark.scheduler.cluster.YarnClientSchedulerBackend.waitForApplication(YarnClientSchedulerBackend.scala:124)
    at   org.apache.spark.scheduler.cluster.YarnClientSchedulerBackend.start(YarnClientSchedulerBackend.scala:64)
    at    org.apache.spark.scheduler.TaskSchedulerImpl.start(TaskSchedulerImpl.scala:144)
    at org.apache.spark.SparkContext.<init>(SparkContext.scala:530)
    at org.apache.spark.examples.SparkPi$.main(SparkPi.scala:29)
    at org.apache.spark.examples.SparkPi.main(SparkPi.scala)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at   sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at   sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)
    at   org.apache.spark.deploy.SparkSubmit$.org$apache$spark$deploy$SparkSubmit$$runMain(SparkSubmit.scala:731)
    at   org.apache.spark.deploy.SparkSubmit$.doRunMain$1(SparkSubmit.scala:181)
    at org.apache.spark.deploy.SparkSubmit$.submit(SparkSubmit.scala:206)
    at org.apache.spark.deploy.SparkSubmit$.main(SparkSubmit.scala:121)
    at org.apache.spark.deploy.SparkSubmit.main(SparkSubmit.scala)
16/04/04 17:27:58 WARN MetricsSystem: Stopping a MetricsSystem that is not running
Exception in thread "main" org.apache.spark.SparkException: Yarn application has already ended! It might have been killed or unable to launch application master.
    at   org.apache.spark.scheduler.cluster.YarnClientSchedulerBackend.waitForApplication(YarnClientSchedulerBackend.scala:124)
    at org.apache.spark.scheduler.cluster.YarnClientSchedulerBackend.start(YarnClientSchedulerBackend.scala:64)
    at   org.apache.spark.scheduler.TaskSchedulerImpl.start(TaskSchedulerImpl.scala:144)
    at org.apache.spark.SparkContext.<init>(SparkContext.scala:530)
    at org.apache.spark.examples.SparkPi$.main(SparkPi.scala:29)
    at org.apache.spark.examples.SparkPi.main(SparkPi.scala)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at   sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)
    at org.apache.spark.deploy.SparkSubmit$.org$apache$spark$deploy$SparkSubmit$$runMain(SparkSubmit.scala:731)
    at org.apache.spark.deploy.SparkSubmit$.doRunMain$1(SparkSubmit.scala:181)
    at org.apache.spark.deploy.SparkSubmit$.submit(SparkSubmit.scala:206)
    at org.apache.spark.deploy.SparkSubmit$.main(SparkSubmit.scala:121)
    at org.apache.spark.deploy.SparkSubmit.main(SparkSubmit.scala)
[hduser@ptfhadoop01v spark-1.6.0]$

请帮助我解决这个问题以及如何在 Yarn 上以客户端或集群模式运行 Spark。

【问题讨论】:

  • 有人可以指定需要为 spark-env.sh 和 spark-defaults.conf 设置的基本配置来启动 spark shell 作为 yarn-client。我找不到任何可参考的示例文件。

标签: hadoop apache-spark hadoop-yarn


【解决方案1】:

现在,我对 SPARK 一无所知,我想知道如何在 Yarn 上运行 Spark。我读到我们可以将它作为 yarn-client 或 yarn-cluster 运行。

强烈建议您阅读 Spark on YARN 的官方文档http://spark.apache.org/docs/latest/running-on-yarn.html

您可以使用spark-shell--master yarn 连接到YARN。您需要在您执行 spark-shell 的机器上拥有正确的配置文件,例如yarn-site.xml.

我应该在集群中的所有节点(NN2 和 DN1)上安装 spark 和 scala 以在 Yarn 客户端或集群上运行 spark 吗?

没有。您无需在 YARN 上安装任何东西,因为 Spark 会为您分发必要的文件。

如果否,那么我如何从 NN1(主名称节点)主机提交 Spark 作业。

spark-shell --master yarn开始,看看是否可以执行以下代码:

(0 to 5).toDF.show

如果您看到类似表格的输出,那么您就完成了。否则,请提供错误。

还在我的 bashrc 文件中创建了 SPARK_JAR 变量。我尝试将 Spark 作业作为 yarn-client 提交,但最终出现如下错误,我不知道我做的是否正确或需要其他设置首先完成。

删除SPARK_JAR 变量。不要使用它,因为它不是必需的,可能会引起麻烦。阅读http://spark.apache.org/docs/latest/running-on-yarn.html 上的官方文档以了解 Spark on YARN 及其他版本的基础知识。

【讨论】:

    【解决方案2】:

    通过将此属性添加到 hdfs-site.xml 中,它解决了问题

    <property>
        <name>dfs.client.failover.proxy.provider.mycluster</name>
        <value>org.apache.hadoop.hdfs.server.namenode.ha.ConfiguredFailoverProxyProvider</value>
    </property>
    

    【讨论】:

      【解决方案3】:

      在客户端模式下,您可以运行如下所示的简单字数统计示例

      spark-submit --class org.sparkexample.WordCount --master yarn-client wordcount-sample-plain-1.0-SNAPSHOT.jar input.txt output.txt
      

      我认为您的 spark-submit 命令有误。没有设置 --master 纱线。 我强烈建议使用自动配置工具来快速设置集群,而不是手动方法。

      请参阅 Cloudera 或 Hortonworks 工具。您可以使用它立即进行设置,并且无需手动进行所有这些配置即可轻松提交作业。

      参考:https://hortonworks.com/products/hdp/

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2016-01-14
        • 2018-08-22
        • 2017-09-01
        • 2016-11-05
        • 2015-03-13
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多