Spark集群权威指南
Spark运行模式
Spark部署模式主要有四种:最简单就是Local模式(单机本地模式)、当然 Spark 还有自带的Standalone模式(使用Spark自带的简单集群管理器)。还有单机伪分布式模式,复杂的则运行在集群中,目前能很好的运行在 YARN模式(使用YARN作为集群管理器)和Mesos模式(使用Mesos作为集群管理器)中。对于大多数情况 Standalone 模式就足够了,如果企业已经有 Yarn 或者 Mesos 环境,也是很方便部署的。需要说明的是,当安装好Spark以后,里面就自带了scala环境。
local(本地模式):常用于本地开发测试,本地还分为local单线程和local-cluster多线程;
standalone(集群模式):典型的Mater/slave模式,不过也能看出Master是有单点故障的;Spark支持ZooKeeper来实现 HA
on yarn(集群模式): 运行在 yarn 资源管理器框架之上,由 yarn 负责资源管理,Spark 负责任务调度和计算
on mesos(集群模式): 运行在 mesos 资源管理器框架之上,由 mesos 负责资源管理,Spark 负责任务调度和计算
on cloud(集群模式):比如 AWS 的 EC2,使用这个模式能很方便的访问 Amazon的 S3;Spark 支持多种分布式存储系统:HDFS 和 S3
分布式部署方式比较
standalone模式自带完整的服务,可单独部署到一个集群中,无需依赖任何其他资源管理系统从一定程度上说,该模式是Mesos和YARN模式的基础
Spark On Mesos模式。这是很多公司采用的模式,官方推荐这种模式。
Spark On YARN模式。这是一种最有前景的部署模式。
参考:http://blog.csdn.net/zhangqiagn1104/article/details/49800541
上面涉及到Spark的许多部署模式,究竟哪种模式好这个很难说,需要根据你的需求,如果你只是测试Spark Application,你可以选择local模式。而如果你数据量不是很多,Standalone 是个不错的选择。当你需要统一管理集群资源(Hadoop、Spark等),可以选择Yarn或mesos,但是这样维护成本就会变高。
在集群模式中会遇到的概念:
应用(Application):构建在Spark上的用户程序,包括驱动程序和集群上的执行器;
应用jar包(Application jar):一个包含用户的Spark应用的jar文件。在一些情况下用户可能会创建一个超级jar包(Uber jar),来包含应用和依赖。用户的jar包不要包含Spark和Hadoop的依赖,这些会在运行时添加;
驱动程序(Driver program):就是执行应用中的main方法并创建SparkContext的进程;
集群管理器(Clustermanager):一个可以在集群上获得资源的外部组件(比如standalone,Mesos和YARN);
部署模式(Deploy mode):部署模式用来分别驱动程序在哪里运行。在集群(cluster)模式,框架将驱动程序启动在急群众。在客户端(client)模式,驱动程序在集群外启动;
工作器节点(Worker node):集群中任何可以运行应用的节点;
执行器(Executor):在工作器节点上运行应用的进程,可以执行任务,保存数据。每个应用都有自己的执行器;
任务(Task):发送给一个执行器的一组计算;
工作(Job):由一组执行Spark行动操作的任务构成的并行计算,可以在驱动程序的日志中看到这个术语;
阶段(Stage):每一个工作分解为若干个小的一组任务叫做阶段(和MapReduce中的map阶段和reduce阶段类似)。
解压并安装Spark
解压Spark
该部分的安装需要在 Hadoop 已经成功安装的基础上,并且要求 Hadoop 已经正常启动。我们将 Spark 安装在 HadoopMaster 节点上。所以下面的所有操作都在HadoopMaster 节点上进行。
Spark版本spark-2.1.1
命令:
sudotar –zxvf /home/hadoop/Desktop/ spark-2.1.1-b