Spark Quick Start (1)

Source: Internet
Author: User

1 Installing Spark

First, go to https://spark.apache.org/downloads.html to select the latest spark version and Hadoop version (in fact we are not using Hadoop for the time being, so any version is ok), then download the package.

After that, unzip the folder to a specific location, for example, I'll name the extracted folder and spark put it in my home folder /home/qyx so I can execute

/home/qyx/spark/bin/spark-shell

To run Spark's terminal. To avoid having to enter a long string of paths each time you open spark, you can add the Spark bin directory to the system path, for example, I wrote ~/.bashrc a file

Export path= $PATH:/home/qyx/spark/bin

So the installation process is so happy to end.

2 Installing SBT

3 Simple test examples

/* Simpleapp.scala */import org.apache.spark.SparkContextimport Org.apache.spark.sparkcontext._import Org.apache.spark.SparkConfobject Simpleapp {  def main (args:array[string]) {    val logFile = "your_spark_home/ Readme.md "//should be some file on your system    val conf = new sparkconf (). Setappname (" Simple Application ")    Val S c = new Sparkcontext (conf)    val logdata = Sc.textfile (LogFile, 2). Cache ()    val numas = logdata.filter (line = Lin E.contains ("a")). Count ()    val numbs = logdata.filter (line = Line.contains ("B")). Count ()    println ("Lines With a:%s, Lines with B:%s ". Format (Numas, numbs)  }}

4 SBT Package file

Name: = "Simple Project" version: = "1.0" scalaversion: = "2.11.5" librarydependencies + = "Org.apache.spark" percent "Spark-core" % "1.4.0"

5 to keep SBT working properly, we need to put Simpleapp.scala and SIMPLE.SBT in a typical SBT project layout folder. As a result, we can package the application code into a jar file and then run the program using the Spark-submit script.

# Your Directory layout should look like this$ find .../simple.sbt./src./src/main./src/main/scala./src/main/scala/ simpleapp.scala# Package a jar containing your application$ SBT ... [INFO] Packaging {..} /{..} /target/scala-2.10/simple-project_2.10-1.0.jar# use Spark-submit to run your application$ your_spark_home/bin/ Spark-submit   --class "Simpleapp"   --master local[4]   Target/scala-2.10/simple-project_2.10-1.0.jar ... Lines with a:46, Lines with b:23

  

Spark Quick Start (1)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.