6 Steps to Setup Apache Spark 1.0.1 (Multi Node Cluster) on CentOS

Before we move ahead lets learn a bit on Setup Apache Spark,

So, What is Apache Spark?

Apache Spark is a fast, real time and extremely expressive computing system which executes job in distributed (clustered) environment.

It is quite compatible with Apache Hadoop and more almost 10x faster than Hadoop MapReduce on Disk Computing and 100x faster using in memory computations. It provides rich APIs in Java, Scala and Python along with Functional Programming capabilities.

This post will give you clear idea on setting up Spark Multi Node cluster on CentOS with Hadoop and YARN.

Before moving forward I assume that you are aware about how to install Java 7 and Apache Hadoop with YARN on CentOS cluster,

Step 1. Download Apache Spark using below commands

Step 2. Configuration in spark-env.sh

Create /home/spark-1.0.1-bin-hadoop2/conf/spark-env.sh and add below lines to the file

Create /home/spark-1.0.1-bin-hadoop2/conf/spark-defaults.conf and add below lines to the file.

Append hostnames of all the slave nodes in /home/spark-1.0.1-bin-hadoop2/conf/slaves file

[Repeat same above step 1 and 2 on other slave nodes (slave1.backtobazics.com in our case)]

Step 3. Start/Stop Spark using below commands

Step 4. Start Spark shell using YARN

Above command will launch spark shell where you can get a Scala prompt. Now you can start writing your spark code command by command and it will executed as soon as you write

Step 5. Creating a sample text file on HDFS for WordCount example

Create a simple text file sample.txt with following content.

Put above file on HDFS using following command.

Step 6. Execute following steps of word count example

After you put your sample text file on HDFS, execute following set of commands which will perform word count on Spark Cluster.

That’s it….. You are done. 🙂

You can access SPARK UI in Browser by below URL
Spark Master URL: http://master.backtobazics.com:8088/

Check my post related to Building Spark Application JAR using Scala and SBT for more information on Submitting Spark job on YARN cluster.

Thank you for reading this post…..!!!!! n Stay tuned for more such posts…..


  1. Thanks for your tutorial.
    1. Do you think the settings are same for ubuntu 12.04.
    2. Do I have to install spark on other hadoop slave nodes or just the master node.

    1. Thanks for reading Ahmad. Here are your answers…

      1. Yes steps and settings are same on ubuntu as well.
      2. Of course you have to install spark on slave nodes. Slave nodes are where your spark worker nodes will run. As i mentioned under Step 2, you need to repeat step 1 and 2 in all of your slave nodes.

      1. My installation is complete. Thanks a lot.
        Now, when I run following command

        ./bin/spark-submit –class my.main.Class –master yarn-cluster

        Error: Must specify a primary resource (JAR or Python or R file)

        I created this direcorty sudo mkdir -p /data/WordCount/src/main/scala/com/backtobazics/spark/wordcount
        after that using chown command change the owner of directory.
        created following file at above path

        package com.backtobazics.spark.wordcount

        import org.apache.spark.{SparkConf, SparkContext}
        import org.apache.spark.SparkContext._

        object ScalaWordCount {
        def main(args: Array[String]) {
        val logFile = “hdfs://maroof:9000/user/hduser/samples/pg20417.txt”
        val sparkConf = new SparkConf().setAppName(“Spark Word Count”)
        val sc = new SparkContext(sparkConf)
        val file = sc.textFile(logFile)
        val counts = file.flatMap(_.split(“\\|”)).map(word => (word, 1)).reduceByKey(_ + _)

        1. Hi Ahmad, I have done some modifications in my current post so please go through it once. And I have tried to answer all of your questions in my recent post Building Spark Application JAR using Scala and SBT. I hope you will get all of your answers there…..

          1. Thank you for your help. I will read them and if you don’t mind, consult you in case on any issues.

            Thanks Again!!!

  2. Thank for your intersted article , I like to make a real example of creating Multi Node (up to 10 nodes) Hadoop 2.6.0 Cluster with YARN with SPARK on ubuntu with an java example of word count example.

    I have another question, i have to make a genetic algorithm to run on hadoop and apache spark , you know that genetic algorithm is iterative with its nature. my genetic algorithm will have and extensive read/worte of many file that contains sentences, what is you idea to make this.

    1. Thanks Sulaiman….

      In case of your query regarding generic algorithm, can you be more specific in terms of what exactly you need to do?

  3. Hi varun,

    I am trying to install spark on my system, bu i am getting “bash: spark-shell: command not found….” could you please provide any solution for this.. i am not able to resolve this.


    1. Hi Girish, Can you tell me exactly at which point you are getting this error? It might be possible that you are directly executing spark-submit command without setting $SPARK_HOME/bin to your $PATH variable. Please try to execute following commands,

      1) $SPARK_HOME/bin/spark-shell –master yarn-client


      2) Set path variable and execute the command
      – export $PATH=$PATH:$SPARK_HOME/bin/
      – spark-shell –master yarn-client

      where $SPARK_HOME = [spark installation directory]

Leave a Reply

Your email address will not be published. Required fields are marked *