STEP 1: Configure YARN properly(yarn-site.xml) with some online reference and then for sanity checking whether YARN is installed properly or not run the below command
yarn jar /opt/hadoop/share/hadoop/mapreduce/hadoop-mapreduce-examples-2.7.3.jar wordcount /tmp/abhijeet/hadoop.in /tmp/abhijeet/out/out.1
If this is working fine then your good to go.
STEP 2: Install Spark with reference to some online content and do the sanity checking using the below command whether spark is installed properly or not
opt/spark/bin/spark-submit --class org.apache.spark.examples.SparkPi --master local[*] /opt/spark/examples/jars/spark-examples_2.11-2.1.1.jar
If this is working fine, it means spark is installed properly.
STEP 3: Now, it's the time to run spark over yarn
Run the below given command
/opt/spark/bin/spark-submit --class org.apache.spark.examples.SparkPi --master yarn --deploy-mode cluster --executor-memory 2G --num-executors 2 /opt/spark/examples/jars/spark-examples_2.11-2.1.1.jar
If this one is working fine then Congratulations!
NOTE: The above given path is local to my system and all the jars used comes with the default package of Hadoop and Spark.