在Ubuntu上安装Apache Spark

Ubuntu 16.04 上安装 Apache Spark 的步骤。
请参考以下链接以获取 Windows 和 Mac 的安装说明。
– 讲解 Spark 应用程序的基础知识和需要首先了解的重要概念:CodeZine

JDK 的安装

$ sudo apt-get install -y openjdk-8-jdk

Spark 安装

将/usr/local/spark设为SPARK_HOME。

$ wget http://ftp.riken.jp/net/apache/spark/spark-1.6.1/spark-1.6.1-bin-hadoop2.6.tgz
$ tar zxvf spark-1.6.1-bin-hadoop2.6.tgz
$ sudo mv spark-1.6.1-bin-hadoop2.6 /usr/local/
$ sudo ln -s /usr/local/spark-1.6.1-bin-hadoop2.6 /usr/local/spark

在 .bashrc 文件中添加以下内容。

export SPARK_HOME=/usr/local/spark
export PATH=$PATH:$SPARK_HOME/bin

设定日志级别

如果未进行任何设置,则日志级别将为INFO,并输出大量的日志,因此需要通过log4j.properties文件来设置日志级别。

$ cd $SPARK_HOME/conf
$ cp log4j.properties.template log4j.properties

建议在 log4j.properties 文件的以下行中将日志级别更改为 WARN。

log4j.rootCategory=INFO, console

使用spark-shell执行样本

计算 Spark 的 README.md 文件中包含的单词数量。

$ spark-shell --master local[*]
(中略)
Welcome to
      ____              __
     / __/__  ___ _____/ /__
    _\ \/ _ \/ _ `/ __/  '_/
   /___/ .__/\_,_/_/ /_/\_\   version 1.6.1
      /_/

Using Scala version 2.10.5 (OpenJDK 64-Bit Server VM, Java 1.8.0_91)
Type in expressions to have them evaluated.
Type :help for more information.
(中略)

scala> val textFile = sc.textFile("/usr/local/spark/README.md")
textFile: org.apache.spark.rdd.RDD[String] = /usr/local/spark/README.md MapPartitionsRDD[1] at textFile at <console>:27

scala> val wordCounts = textFile.flatMap(line => line.split(" ")).map(word => (word, 1)).reduceByKey((a, b) => a + b)
wordCounts: org.apache.spark.rdd.RDD[(String, Int)] = ShuffledRDD[4] at reduceByKey at <console>:29

scala> wordCounts.collect()
res0: Array[(String, Int)] = Array((package,1), (For,2), (Programs,1), (processing.,1), ...(中略)...,  (>>>,1), (programming,1), (T...
scala>

仅提供一个选项。

    Spark Overview