Apache Spark 3.0.0 Installation on Linux Guide

access_time 4 months ago visibility992 comment 0

This article provides step by step guide to install the latest version of Apache Spark 3.0.0 on a UNIX alike system (Linux) or Windows Subsystem for Linux (WSL). These instructions can be applied to Ubuntu, Debian, Red Hat, OpenSUSE, MacOS, etc. 

Prerequisites

Windows Subsystem for Linux (WSL)

If you are planning to configure Spark 3.0 on WSL, follow this guide to setup WSL in your Windows 10 machine:

Install Windows Subsystem for Linux on a Non-System Drive

Hadoop 3.3.0

This article will use Spark package without pre-built Hadoop. Thus we need to ensure a Hadoop environment is setup first.

If you choose to download Spark package with pre-built Hadoop, Hadoop 3.3.0 configuration is not required. 

Follow one of the following articles to install Hadoop 3.3.0 on your UNIX-alike system:

OpenJDK 1.8

Java JDK 1.8 needs to be available in your system. 

In the Hadoop installation articles, it includes the steps to install OpenJDK.

Run the following command to verify Java environment:

$ java -version
openjdk version "1.8.0_212"
OpenJDK Runtime Environment (build 1.8.0_212-8u212-b03-0ubuntu1.18.04.1-b03)
OpenJDK 64-Bit Server VM (build 25.212-b03, mixed mode)

Now let’s start to configure Apache Spark 3.0.0 in a UNIX-alike system. 

Download binary package

Visit Downloads page on Spark website to find the download URL.


For me, the closest location is: http://apache.mirror.amaze.com.au/spark/spark-3.0.0/spark-3.0.0-bin-without-hadoop.tgz.

Download the binary package using the following command:

wget http://apache.mirror.amaze.com.au/spark/spark-3.0.0/spark-3.0.0-bin-without-hadoop.tgz

Unpack the binary package

Unpack the package using the following command:

mkdir ~/hadoop/spark-3.0.0
tar -xvzf spark-3.0.0-bin-without-hadoop.tgz -C ~/hadoop/spark-3.0.0 --strip 1

The Spark binaries are unzipped to folder ~/hadoop/spark-3.0.0.

Setup environment variables

Setup SPARK_HOME environment variables and also add the bin subfolder into PATH variable. We also need to configure Spark environment variable SPARK_DIST_CLASSPATH to use Hadoop Java class path. 

Run the following command to change .bashrc file:

vi ~/.bashrc

Add the following lines to the end of the file:

export SPARK_HOME=~/hadoop/spark-3.0.0                                
export PATH=$SPARK_HOME/bin:$PATH # Configure Spark to use Hadoop classpath export SPARK_DIST_CLASSPATH=$(hadoop classpath)
# Source the modified file to make it effective:
source  ~/.bashrc

Setup Spark default configurations

Run the following command to create a Spark default config file:

cp $SPARK_HOME/conf/spark-defaults.conf.template $SPARK_HOME/conf/spark-defaults.conf

Edit the file to add some configurations use the following commands:

vi $SPARK_HOME/conf/spark-defaults.conf


Make sure you add the following line:

spark.driver.host	localhost

There are many other configurations you can do. Please configure them as necessary. 

spark.eventLog.dir and spark.history.fs.logDirectory

These two configurations can be the same or different. The first configuration is used to write event logs when Spark application runs while the second directory is used by the historical server to read event logs. 

Now let's do some verifications to ensure it is working.

Run Spark interactive shell

Run the following command to start Spark shell:

spark-shell

The interface looks like the following screenshot:


By default, Spark master is set as local[*] in the shell.

Run with built-in examples

Run Spark Pi example via the following command:

run-example SparkPi 10

The output looks like the following:


In this website, I’ve provided many Spark examples. You can practice following those guides.

Spark context Web UI

When a Spark session is running, you can view the details through UI portal. As printed out in the interactive session window, Spark context Web UI available at http://localhost:4040. The URL is based on the Spark default configurations. The port number can change if the default port is used. 

The following is a screenshot of the UI:


Enable Hive support

If you’ve configured Hive in WSL, follow the steps below to enable Hive support in Spark.

Copy the Hadoop core-site.xml and hdfs-site.xml and Hive hive-site.xml configuration files into Spark configuration folder:

cp $HADOOP_HOME/etc/hadoop/core-site.xml $SPARK_HOME/conf/
cp $HADOOP_HOME/etc/hadoop/hdfs-site.xml $SPARK_HOME/conf/
cp $HIVE_HOME/conf/hive-site.xml $SPARK_HOME/conf/

And then you can run Spark with Hive support (enableHiveSupport function):

from pyspark.sql import SparkSession
appName = "PySpark Hive Example" master = "local[*]" spark = SparkSession.builder \
             .appName(appName) \
             .master(master) \
             .enableHiveSupport() \
             .getOrCreate()
# Read data using Spark df = spark.sql("show databases") df.show()

For more details, please refer to this page: Read Data from Hive in Spark 1.x and 2.x.

Spark history server

Run the following command to start Spark history server:

$SPARK_HOME/sbin/start-history-server.sh

Open the history server UI (by default: http://localhost:18080/) in browser, you should be able to view all the jobs submitted. 

check Congratulations! You have successfully configured Spark in your UNIX-alike system. Have fun with Spark 3.0.0.
info Last modified by Administrator at 4 months ago copyright This page is subject to Site terms.
Like this article?
Share on

Please log in or register to comment.

account_circle Log in person_add Register

Log in with external accounts

Want to publish your article on Kontext?

Learn more

Kontext Column

Created for everyone to publish data, programming and cloud related articles.
Follow three steps to create your columns.


Learn more arrow_forward

More from Kontext

local_offer zeppelin local_offer spark local_offer linux local_offer WSL local_offer big-data-on-wsl

visibility 3207
thumb_up 0
access_time 2 years ago

This page summarizes the steps to install Zeppelin version 0.7.3 on Windows 10 via Windows Subsystem for Linux (WSL). When running Zeppelin in Ubuntu, the server may pick up one host address that is not accessible, for example 169.254.148.100, and the the remote interpreter connection cannot be ...

local_offer linux local_offer WSL local_offer ubuntu local_offer big-data-on-wsl

visibility 12752
thumb_up 5
access_time 2 years ago

This page shows how to install Windows Subsystem for Linux (WSL) system on a non-system drive manually. Open PowerShell as Administrator and run the following command to enable WSL feature: Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux Run the following ...

local_offer python local_offer spark

visibility 1150
thumb_up 0
access_time 2 years ago

This code snippet shows how to convert string to date.

About column

Apache Spark installation guides, performance tuning tips, general tutorials, etc.

*Spark logo is a registered trademark of Apache Spark.

rss_feed Subscribe RSS