LoginSignup
10
12

More than 5 years have passed since last update.

Ubuntu への Apache Spark のインストール

Last updated at Posted at 2016-05-09

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>

参考

10
12
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
10
12