--- layout: global title: Running Spark on Mesos --- # Why Mesos Spark can run on hardware clusters managed by [Apache Mesos](http://mesos.apache.org/). The advantages of deploying Spark with Mesos include: - dynamic partitioning between Spark and other [frameworks](https://mesos.apache.org/documentation/latest/mesos-frameworks/) - scalable partitioning between multiple instances of Spark # How it works In a standalone cluster deployment, the cluster manager in the below diagram is a Spark master instance. When using Mesos, the Mesos master replaces the Spark master as the cluster manager.
Now when a driver creates a job and starts issuing tasks for scheduling, Mesos determines what machines handle what tasks. Because it takes into account other frameworks when scheduling these many short-lived tasks, multiple frameworks can coexist on the same cluster without resorting to a static partitioning of resources. To get started, follow the steps below to install Mesos and deploy Spark jobs via Mesos. # Installing Mesos Spark {{site.SPARK_VERSION}} is designed for use with Mesos {{site.MESOS_VERSION}} and does not require any special patches of Mesos. If you already have a Mesos cluster running, you can skip this Mesos installation step. Otherwise, installing Mesos for Spark is no different than installing Mesos for use by other frameworks. You can install Mesos using either prebuilt packages or by compiling from source. ## Prebuilt packages The Apache Mesos project only publishes source package releases, no binary releases. But other third party projects publish binary releases that may be helpful in setting Mesos up. One of those is Mesosphere. To install Mesos using the binary releases provided by Mesosphere: 1. Download Mesos installation package from [downloads page](http://mesosphere.io/downloads/) 2. Follow their instructions for installation and configuration The Mesosphere installation documents suggest setting up ZooKeeper to handle Mesos master failover, but Mesos can be run without ZooKeeper using a single master as well. ## From source To install Mesos directly from the upstream project rather than a third party, install from source. 1. Download the Mesos distribution from a [mirror](http://www.apache.org/dyn/closer.cgi/mesos/{{site.MESOS_VERSION}}/) 2. Follow the Mesos [Getting Started](http://mesos.apache.org/gettingstarted) page for compiling and installing Mesos **Note:** If you want to run Mesos without installing it into the default paths on your system (e.g., if you lack administrative privileges to install it), you should also pass the `--prefix` option to `configure` to tell it where to install. For example, pass `--prefix=/home/user/mesos`. By default the prefix is `/usr/local`. ## Verification To verify that the Mesos cluster is ready for Spark, navigate to the Mesos master webui at port `:5050` Confirm that all expected machines are present in the slaves tab. # Connecting Spark to Mesos To use Mesos from Spark, you need a Spark distribution available in a place accessible by Mesos, and a Spark driver program configured to connect to Mesos. ## Uploading Spark Distribution When Mesos runs a task on a Mesos slave for the first time, that slave must have a distribution of Spark available for running the Spark Mesos executor backend. A distribution of Spark is just a compiled binary version of Spark. The Spark distribution can be hosted at any Hadoop URI, including HTTP via `http://`, [Amazon Simple Storage Service](http://aws.amazon.com/s3) via `s3://`, or HDFS via `hdfs:///`. To use a precompiled distribution: 1. Download a Spark distribution from the Spark [download page](https://spark.apache.org/downloads.html) 2. Upload to hdfs/http/s3 To host on HDFS, use the Hadoop fs put command: `hadoop fs -put spark-{{site.SPARK_VERSION}}.tar.gz /path/to/spark-{{site.SPARK_VERSION}}.tar.gz` Or if you are using a custom-compiled version of Spark, you will need to create a distribution using the `make-distribution.sh` script included in a Spark source tarball/checkout. 1. Download and build Spark using the instructions [here](index.html) 2. Create a Spark distribution using `make-distribution.sh --tgz`. 3. Upload archive to http/s3/hdfs ## Using a Mesos Master URL The Master URLs for Mesos are in the form `mesos://host:5050` for a single-master Mesos cluster, or `zk://host:2181` for a multi-master Mesos cluster using ZooKeeper. The driver also needs some configuration in `spark-env.sh` to interact properly with Mesos: 1. In `spark.env.sh` set some environment variables: * `export MESOS_NATIVE_LIBRARY=