【GCE/GCS】GCEでGCSのデータにアクセスし、jupyter notebookを起動
経緯
ミニマムで始められるデータ分析基盤構築って何だろう?とメンバーと話す機会があり、GCEにGCSのデータ見に行って、jupyter notebookでやればいんじゃね?と思い、やってみました。
実現したいこと
GCEからGCSのストレージにアクセスし、jupyter notebookで分析する
手順
- GCE VMインスタンス構築
- python環境構築(jupyter notebook含む)
- GCS FUSEでフォルダをマウント
- 3でマウントしたファイルにjupyter notebookでアクセス
GCE構築
VMインスタンス構築
python環境構築
jupyter notebookを実行できる環境にします。
まず gcloud
コマンドで ssh
できるように確認していきます。
pythonの環境構築をしていきます。
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
sudo python get-pip.py
sudo apt-get install -y build-essential autoconf libtool pkg-config python-opengl python-imaging python-pyrex python-pyside.qtopengl idle-python2.7 qt4-dev-tools qt4-designer libqtgui4 libqtcore4 libqt4-xml libqt4-test libqt4-script libqt4-network libqt4-dbus python-qt4 python-qt4-gl libgle3
jupyter notebookをインストールします。
sudo python -m pip install jupyter
GCEでJupyterを構築 | GMOアドパートナーズグループ TECH BLOG byGMO
GCS FUSEでフォルダをマウント
GCEでGCSの情報を取得していきます。
適当にフォルダを作成
mkdir test
gcsのバケットをマウント
gcsfuse example-bucket test
このコマンド実行後、GCSのバケットに配置してあるファイルが全てマウントされます。
便利すぎるわこれw
Cloud Storage FUSE | Google Cloud
jupyter notebookでマウントしたファイルにアクセス
ターミナル2つ立ち上げておきます。
1つは、下記で実行。
# GCEで実行すること
$ gcloud beta compute ssh --zone "ゾーン名" "VMインスタンスのサーバー名" --project "プロジェクト名"
$ jupyter notebook
もう1つは、下記で実行。
$ gcloud beta compute ssh --zone "ゾーン名" "VMインスタンスのサーバー名" --project "プロジェクト名" -- -N -L 8888:localhost:8888
Google Compute Engine で SSH Port Forwarding する - CUBE SUGAR CONTAINER
GCEのインスタンス作成からssh接続まで - Qiita
sshポートフォワーディング - Qiita
結果
localhost:8888
にアクセスすると、jupyter notebookにアクセスできているはず!
Author And Source
この問題について(【GCE/GCS】GCEでGCSのデータにアクセスし、jupyter notebookを起動), 我々は、より多くの情報をここで見つけました https://qiita.com/wqwq/items/2af0df174e5b9a42a97f著者帰属:元の著者の情報は、元のURLに含まれています。著作権は原作者に属する。
Content is automatically searched and collected through network algorithms . If there is a violation . Please contact us . We will adjust (correct author information ,or delete content ) as soon as possible .