在纱线客户端上运行Spark

时间:2016-04-04 10:01:34

标签: hadoop apache-spark yarn

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

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-shell

现在,我对SPARK一无所知,我想知道如何在纱线上运行Spark。我已经读过,我们可以将它作为纱线客户端或纱线集群运行。

我应该安装火花&群集中的所有节点(NN2和DN1)上的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 Job作为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]$

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

3 个答案:

答案 0 :(得分:2)

  

现在,我对SPARK一无所知,我想知道如何在纱线上运行Spark。我已经读过,我们可以将它作为纱线客户端或纱线集群运行。

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

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

  

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

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

  

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

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

(0 to 5).toDF.show

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

  

还在我的bashrc文件中创建了SPARK_JAR变量。我试图将Spark Job作为yarn-client提交但我最终得到如下错误,我不知道我是否正确地做了这一切或需要其他设置是先完成。

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

答案 1 :(得分:0)

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

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

答案 2 :(得分:-1)

在客户端模式下,您可以运行类似下面的简单字数示例

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

我认为你在那里错误地提出了spark-submit命令。没有 - 主纱设置。 我强烈建议使用自动配置工具快速设置群集,而不是手动方法。

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

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