2018年1月6日土曜日

[Jupyter Notebook] Google Cloud Platformで試してみる

【環境】
Google Cloud Platform(GCP)[VMインスタンス]上で実行
OS : Linux(Debian 6.3.0-18)
Python3 (3.5.3) をインストール済み
Jupyter Notebookとは、ノートブックと呼ばれる形式で作成したプログラムを実行し、実行結果を記録しながら、データの分析作業を進めるためのツールです。

これをGoogle Cloud Platform(GCP)上で試してみたのでメモ。


まずインストールのため権限を与える
$ sudo su -
パッケージリストの更新
# apt-get update
jupyterのインストール
# pip3 install jupyter

jupyterの起動
# jupyter notebook
[C NotebookApp] Running as root is not recommended. Use --allow-root to bypass.

ルートで起動することはお勧めできないと、起動に失敗...
とりあえずコマンドをつけて実行
# jupyter notebook --allow-root
[I NotebookApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).
[W NotebookApp] No web browser found: could not locate runnable browser.
[C NotebookApp] Copy/paste this URL into your browser when you connect for the first time,
to login with a token:
http://localhost:8888/?token=xxxxxx

localhostの部分をGCPの外部IPに変更し、ブラウザでアクセスしてみるもアクセスエラー

ポートが空いてないからかなと、ポートを開ける
[GCP]ポータル - [VPCネットワーク] - [ファイアーウォール ルール]

「tcp:8888」を作成、

インスタンスにタグを設定し、インスタンスの再起動。

いざ、実行し、アクセス!
# jupyter notebook --allow-root
[C NotebookApp] Copy/paste this URL into your browser when you connect for the first time,
to login with a token:
http://localhost:8888/?token=xxxxxx

まだアクセスエラー...

どうやらjupyterの設定をするのを忘れてました。
Running a notebook server
ここを見ながら、設定を進めます。

まず、以下を実行し、パスワードを設定します。
# jupyter notebook password
Enter password: ******
Verify password: ******
[NotebookPasswordApp] Wrote hashed password to /root/.jupyter/jupyter_notebook_config.json
jsonファイルにパスワードが出力されるので、viなどで表示してメモ。
{
  "NotebookApp": {
    "password": "sha1:9c69************78e"
  }
}

次に、以下を実行すると設定ファイルが作成される。
# jupyter notebook --generate-config
Writing default config to: /root/.jupyter/jupyter_notebook_config.py
設定ファイルをviなどで編集。
編集する部分は以下
c.NotebookApp.ip = '*'
c.NotebookApp.password = u'先ほどメモったパスワード'
c.NotebookApp.open_browser = False
c.NotebookApp.port = 8888

さて、これでもう一度、実行してアクセス!
# jupyter notebook --allow-root
[I NotebookApp] http://[all ip addresses on your system]:8888/

やっと起動できました!


また少しづつ遊ぼうと思います。

次の起動のためのメモ
$ sudo su -                                   #root権限をつける
# jupyter notebook --allow-root    #jyupyterを実行
# cd ~               #通常ユーザディレクトリに保存される

バックグラウンドでの実行
$ sudo su -

バックエンド実行([nohup *** &]と実行するとバックエンド実行となる)
# nohup jupyter notebook --allow-root &    #jyupyterを実行

バックグラウンドの状況を確認
# ps axf u | grep jupyter
バックグラウンド実行している処理を止める([PID]は[ps u]にて確認した数値)
# kill -KILL [PID]

【参考】


0 件のコメント:

コメントを投稿