0
1

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.

macOS+Vagrant(CentOS)でpysparkを動かす

Last updated at Posted at 2019-09-03

はじめに

macOSにVirturalBoxインストールしてCentOSを動かし、Apache sparkをダウンロードしてpysparkの実行環境を作る

Vagrantのダウンロード

バージョン確認

$ vagrant --version
Vagrant 2.2.5

VirtualBoxのダウンロード

VirturalBox
https://www.virtualbox.org/wiki/Downloads

Boxの追加

CentOS 7.2 x64 を使用します。

$ vagrant box add centos72 https://github.com/CommanderK5/packer-centos-template/releases/download/0.7.2/vagrant-centos-7.2.box

Boxの確認

$ vagrant box list
centos72 (virtualbox, 0)

VMの作成&起動

$ mkdir -p ~/Vagrant/CentOS72
$ cd ~/Vagrant/CentOS72
$ vagrant init centos72

Vagrantfileの編集

~/Vagrant/CentOS72の中に、Vagrantfileというファイルが作成されているので、
下の3つの部分の#を外し、数値を設定する

config.vm.network "forwarded_port", guest: 8888, host: 8888

config.vm.network "private_network", ip: "192.168.33.10"

config.vm.provider "virtualbox" do |vb|
  vb.memory = "4096"
end

Vagrantの起動とSSH接続

※ログインパスワードは「vagrant」です

$ vagrant up
$ ssh vagrant@192.168.33.10

必要コンポーネントのインストール

$ sudo yum install -y git git-core java-1.8.0-openjdk epel-release python-pip gcc python-devel libevent-devel

Sparkのインストール

※2019/9/1時点の最新版のインストール

$ sudo su -
# wget https://www-eu.apache.org/dist/spark/spark-2.4.4/spark-2.4.4-bin-hadoop2.7.tgz 

ファイルの解凍とシンボリックリンクの作成

# tar xvzf spark-2.4.4-bin-hadoop2.7.tgz
# mv spark-2.4.4-bin-hadoop2.7 /usr/local
# ln -s /usr/local/spark-2.4.4-bin-hadoop2.7/ /usr/local/spark

環境変数の設定

※vagrantユーザの.bashrcにも記載してください

# export SPARK_HOME=/usr/local/spark
# export PATH=${SPARK_HOME}/bin:${PATH}
# export PYTHONPATH=${SPARK_HOME}/python/:${SPARK_HOME}/python/lib/py4j-0.10.4-src.zip:${PYTHONPATH}
# source ~/.bashrc

Pythonのインタラクティブシェルで起動する

$ pyspark
0
1
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
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?