Spark运行模式之Spark on Yarn

Spark的四种运行模式

特点:不管使用什么模式,Spark应用程序的代码是一样的,只需要通过参数--master来指定

  • local
  • standalone  是spark自带的,如果一个集群式standalone模式,那么就需要在堕胎机器上同时部署spark环境
  • yarn,统一使用YARN进行整个集群作业的资源调度
  • mesos

Spark ON Yarn 概述

  •  spark支持可插拔的集群管理模式
  •  对于yarn而言,spark application仅仅是个客户端而已

Spark ON Yarn的两种模式对比

spark on yarn 之client模式

客户端通过driver 在集群中申请到资源后, 还需要将程序发送到各个worker节点,所以driver和集群之间的联系是不能断的。client是不能退出的。

日志信息会在控制台输出,方便测试

Yarn的ApplicationMaster只负责资源调度

spark on yarn 之cluster模式

driver是运行在ApplicationMaster中

clinet只要提交完作业就可以关掉,因为作业已经提交到yarn上

ApplicationMaster不仅需要调度资源,还需要调度作业,因为driver是运行在ApplicationMaster中

运行输出日志在终端是看不到的,因为日志是在driver上。只能 通过yarn  logs -application_id **

测试验证

设置HADOOP_CONF_DIR或者是YARN_CONF_DIR

如果想运行spark在yarn之上,那就必须要设置HADOOP_CONF_DIR或者是YARN_CONF_DIR

官网给出的解释如下:

 yarn	Connect to a YARN cluster in client or cluster mode depending on the value of --deploy-mode. 
 The cluster location will be found based on the HADOOP_CONF_DIR or YARN_CONF_DIR variable.
 
1:export HADOOP_CONF_DIR=/home/hadoop/app/hadoop-2.6.0-cdh5.7.0/etc/hadoop
2:$SPARK_HOME/conf/spark-env.sh中配置上述选项

启动hadoop服务

[hadoop@hadoop000 hadoop-2.6.0-cdh5.7.0]$ sbin/start-all.sh 
This script is Deprecated. Instead use start-dfs.sh and start-yarn.sh
18/09/29 21:08:29 WARN util.NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable
Starting namenodes on [hadoop000]

 基于Client模式提交Spark任务

./bin/spark-submit \
--class org.apache.spark.examples.SparkPi \
--master yarn \
--executor-memory 1G \
--num-executors 1 \
/home/hadoop/app/spark-2.1.0-bin-2.6.0-cdh5.7.0/examples/jars/spark-examples_2.11-2.1.0.jar \
4

验证Client模式

18/09/29 21:23:32 INFO scheduler.DAGScheduler: ResultStage 0 (reduce at SparkPi.scala:38) finished in 36.122 s
18/09/29 21:23:33 INFO cluster.YarnScheduler: Removed TaskSet 0.0, whose tasks have all completed, from pool 
18/09/29 21:23:33 INFO scheduler.DAGScheduler: Job 0 finished: reduce at SparkPi.scala:38, took 38.391304 s
Pi is roughly 3.143197857994645

基于Cluster模式提交任务

./bin/spark-submit \
--class org.apache.spark.examples.SparkPi \
--master yarn-cluster \
--executor-memory 1G \
--num-executors 1 \
/home/hadoop/app/spark-2.1.0-bin-2.6.0-cdh5.7.0/examples/jars/spark-examples_2.11-2.1.0.jar \
4

猜你喜欢

转载自blog.csdn.net/sinat_37513998/article/details/82903172