首页 > 技术文章 > Spark 的四种模式

yanxun1 2018-10-17 09:48 原文

1.spark主要有四种运行模式:Local、standalone、yarn、mesos。

  1)Local模式:在一台机器上,一般用于开发测试

  2)standalone模式:完全独立的spark集群,不依赖其他集群,分为Master和work。

    客户端向Master注册应用,Master向work发送消息,依次启动Driver,executor,Driver负责向executors发送任务消息。

  3)yarn模式:依赖于hadoop集群,yarn资源调度框架,将应用提交给yarn,在ApplactionMaster(相当于Stand alone模式中的Master)中运行driver,在集群上调度资源,开启excutor执行任务。

  4)Spark on Mesos模式:类似于yarn模式,运行在Mesos集群上(MesosApache下的开源分布式资源管理框架,它被称为是分布式系统的内核。Mesos最初是由加州大学伯克利分校的AMPLab开发的,后在Twitter得到广泛使用。)

2、启动方式:sparkShell

spark-shell通过不同的参数控制采用何种模式进行。 涉及两个参数:

--master MASTER_URL         spark://host:port, mesos://host:port, yarn, or local.
--deploy-mode DEPLOY_MODE   Whether to launch the driver program locally ("client") or
                            on one of the worker machines inside the cluster ("cluster")
                            (Default: client).

  1)本地模式

./spark-shell --master local
./spark-shell --master local[2]  # 本地运行,两个worker线程,理想状态下为本地CPU core数

  2)standalone模式

./spark-shell --master spark://192.168.1.10:7077

  3)yarn模式

./spark-shell --master yarn
./spark-shell --master yarn-client
#不支持这种模式
#./spark-shell --master yarn-cluster
./spark-shell --master yarn --deploy-mode client
#不支持这种模式
#./spark-shell --master yarn --deploy-mode cluster

spark job部署模式:

通过启动spark-submit 形式提交作业任务时通过自定参数来指定作业部署模式。

eg:

//client模式
spark-submit --master yarn --deploy-mode client --class xxx --executor-memory 1g --executor-cores 2 --num-executors 4 xxx.jar 1000
//cluster模式 spark-submit --master yarn --deploy-mode cluster --class xxx --executor-memory 1g --executor-cores 2 --num-executors 4 xxx.jar 1000

------------------------

1.client

driver程序运行在client端。

2.cluster

driver程序运行在某个worker上。

注:spark-shell只能以client方式启动。

 

 

 

 

 

 

 

 

 

 

 

 

 

 

  

 

 

推荐阅读