- 首先建立pyspark的profile檔案,這個步驟會在ipython的設定檔中新增一個profile檔,名稱叫做pyspark
$ ipython profile create pyspark
- 接著修改這個檔案
$ vi /.ipython/profile_pyspark/ipython_notebook_config.py
- 在原本的設定檔中增加以下指令
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Configure the necessary Spark environment. pyspark needs SPARK_HOME setup | |
# so it knows how to start the Spark master and some local workers for you to use. | |
import os | |
# Fill this in with the path to the spark-0.9.1-bin-cdh4 folder you just downloaded | |
# (e.g., /home/saasbook/spark-0.9.1-bin-cdh4) | |
path_to_spark = "/usr/local/spark" | |
#os.environ['SPARK_HOME'] = path_to_spark | |
# Set the python path so that we know where to find the pyspark files. | |
import sys | |
path_to_pyspark = os.path.join(path_to_spark, "python") | |
path_to_py4j = "/usr/local/spark/python/lib/py4j-0.8.2.1-src.zip" | |
sys.path.insert(0, path_to_pyspark) | |
sys.path.insert(0, path_to_py4j) |
- 設定好後再啟動ipython notebook,就可以run Spark了
$ ipython notebook --ip=sandbox --port=8088 --profile pyspark
- 啟動畫面~
- 開一個新的notebook,來試試看(這是在本機執行唷~)
- 然後回到docker上看一下,果然可以順利執行!
- 設定好後就可以按exit退出container,把我們剛剛的設定儲存起來.
- 看一下剛剛設定好的container
$ docker ps -a
- 接著commit這個設定,把container存成image,這樣以後就可以直接呼叫他,不用重新設定了>"<
$ docker commit <container id> <myimages/image_name:tag>
- 用docker images查看一下,sequenceiq/spark:1.2.0是原本的images,python和pyspark是我之後自己commit的images
- 未來如果您想要啟動pyspark,可以用
$ docker run -i -t -h sandbox -p 8080:8080 sequenceiq/spark:pyspark bash
or
$ docker run -d -h sandbox -p 8080:8080 sequenceiq/spark:pyspark
ipython notebook --ip=sandbox --port=8088 --profile pyspark
- 上面那行是進入互動式介面,下面那行是讓docker container在背景執行,但是仍然可以透過遠端登入ipython notebook
椰~~終於寫完了~~Docker真的很好玩XD,對於開發和測試也的確相當方便,難怪迅速竄紅!
您好,想請教一下,我按照您的步驟一到三都做完了。
回覆刪除但是我的http://192.168.59.103:8089/tree# 畫面跟您的不一樣。
我的是顯示jupyter 的logo,畫面的右邊Notebooks 顯示的是反白無法點選,想請教您
這可能是我哪一步驟有問題呢。
我是pull sequenceiq/spark:1.2.1 版本
感謝
不好意思今天才回你,方便請您貼上訊息畫面嘛XD 這樣的資訊太少有點難判斷
刪除我猜問題可能出再iypthon沒有裝好? 可以檢查一下能不能獨立啟動ipython notebook
我的ipython變成 jupyter後,如果在import的時候也會出現錯誤。
刪除---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
in ()
----> 1 from pyspark import SparkContext
ImportError: No module named pyspark
找不到套件,應該是啟動設定檔那邊的問題,可以現在ipython 裡面手動加入pyspark的路徑,看看能不能import
刪除謝謝回覆~請問是在哪邊加入pyspark路徑?
刪除