19
18

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Mac に Ubuntu + CDH5 + Apache Spark 環境構築

Last updated at Posted at 2014-11-29

(参考)
VirtualBoxとCDH5でお手軽Apache Spark検証環境の構築
Installing CDH 5 with YARN on a Single Linux Node in Pseudo-distributed mode

VirtualBox インストール

OS X 用のものをダウンロードしてインストール
https://www.virtualbox.org/wiki/Downloads

Ubuntu 仮想環境作成

Vagrantfile 作成
# -*- mode: ruby -*-
# vi: set ft=ruby :

VAGRANTFILE_API_VERSION = "2"

Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
  config.vm.box = "ubuntu"
  config.vm.box_url = "(VirtualBox の Ubuntu → http://www.vagrantbox.es/ 参照)"

  config.vm.provider "virtualbox" do |vbox|
    vbox.name = "cdh5"
    vbox.cpus = 4
    vbox.memory = 6144
  end
  
  config.vm.network :forwarded_port, guest: 50070, host: 50070
end

メモリは 6GB にしてます。4GB だと動きませんでした。

仮想環境構築
$ vagrant up
$ vagrant ssh
サービス管理ツール入れとく
$ sudo apt-get install -y sysv-rc-conf

CDH5 インストール

Oracle JDK7 インストール
$ sudo apt-get update
$ sudo apt-get install -y python-software-properties
$ sudo add-apt-repository ppa:webupd8team/java
$ sudo apt-get update
$ sudo apt-get install -y oracle-java7-installer
CDH5 (擬似分散モード) インストール
$ cd ~
$ wget http://archive.cloudera.com/cdh5/one-click-install/trusty/amd64/cdh5-repository_1.0_all.deb
$ sudo dpkg -i cdh5-repository_1.0_all.deb
$ sudo apt-get update
$ sudo apt-get install hadoop-conf-pseudo
HDFS のフォーマット
$ sudo -u hdfs hdfs namenode -format
HDFS サービスの起動
# service hadoop-hdfs-datanode start
# service hadoop-hdfs-namenode start
# service hadoop-hdfs-secondarynamenode start

確認
# sysv-rc-conf --list | grep hadoop
# service hadoop-hdfs-datanode status
# service hadoop-hdfs-namenode status
# service hadoop-hdfs-secondarynamenode status
ブラウザから確認
50070 ポート開ける
# ufw status
# ufw enable
# ufw status
# ufw allow 50070/tcp

ブラウザからアクセス
http://localhost:50070/
ssh (Port:22) 許可設定
# ufw allow 22/tcp
必要な HDFS ディレクトリ作成
$ sudo /usr/lib/hadoop/libexec/init-hdfs.sh

確認
$ sudo -u hdfs hadoop fs -ls -R /
YARN サービスの起動
# service hadoop-yarn-resourcemanager start 
# service hadoop-yarn-nodemanager start 
# service hadoop-mapreduce-historyserver start

確認
# sysv-rc-conf --list | grep hadoop
# service hadoop-yarn-resourcemanager status
# service hadoop-yarn-nodemanager status
# service hadoop-mapreduce-historyserver status
ユーザーの作成
$ sudo adduser <username>
$ sudo -u hdfs hadoop fs -mkdir /user/<username>
$ sudo -u hdfs hadoop fs -chown <username> /user/<username>
サンプルアプリケーションの実行
# su - <username>
$ hadoop fs -mkdir input
$ hadoop fs -put /etc/hadoop/conf/*.xml input
$ hadoop fs -ls input
$ export HADOOP_MAPRED_HOME=/usr/lib/hadoop-mapreduce
ジョブ実行
$ hadoop jar /usr/lib/hadoop-mapreduce/hadoop-mapreduce-examples.jar grep input output23 'dfs[a-z.]+'

確認
$ hadoop fs -ls
$ hadoop fs -ls output23
$ hadoop fs -cat output23/part-r-0000

Apache Spark インストール

いろいろインストール
$ sudo apt-get install -y spark-core
$ sudo apt-get install -y spark-master
$ sudo apt-get install -y spark-worker
$ sudo apt-get install -y spark-history-server
$ sudo apt-get install -y spark-python
サービスの起動
$ sudo service spark-master start
$ sudo service spark-worker start 

さぁ、起動

$ spark-shell
/usr/lib/spark/bin/spark-shell: line 44: /usr/lib/spark/bin/utils.sh: No such file or directory

(´・ω・`)
Ubuntu + CDH 5.2.0 でのバグだそうです。 該当のファイルを GitHub から直接持ってきます。

# cd /usr/lib/spark/bin/
# wget https://raw.githubusercontent.com/apache/spark/branch-1.1/bin/utils.sh
# chmod +x utils.sh

今度こそ

$ spark-shell

Welcome to
      ____              __
     / __/__  ___ _____/ /__
    _\ \/ _ \/ _ `/ __/  '_/
   /___/ .__/\_,_/_/ /_/\_\   version 1.1.0
      /_/

Using Scala version 2.10.4 (Java HotSpot(TM) 64-Bit Server VM, Java 1.7.0_72)
Spark context available as sc.

おめでとうございます。

19
18
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
19
18

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?