LoginSignup
0
1

More than 3 years have passed since last update.

GPUサーバ(リモートサーバ)上でjupyter notebookを起動する

Last updated at Posted at 2020-09-02

概要

AWSのGPUインスタンスを用いてjupyter notebookを起動するまでを記載する。

環境

・mac OS Catalina 10.15.6
・AWS Deep Learning AMI (Ubuntu 18.04)

手順

インスタンス作成

○EC2インスタンスを作成する
AMI:AWS Deep Learning AMI (Ubuntu 18.04)
インスタンスタイプ:GPU インスタンス p2.xlarge
ストレージサイズ (GiB):200
あとはデフォルト

インスタンスの作成に失敗 下記エラーが

You have requested more vCPU capacity than your current vCPU limit of 4 allows for the instance bucket that the specified instance type belongs to. Please visit http://aws.amazon.com/contact-us/ec2-request to request an adjustment to this limit.

どうやらインスタンス制限がかかっている模様。キャパシティをあげる申請を行う。

○下記サイトを利用すると引き上げ容量を計算し、申請画面へと遷移することができる。
https://ap-northeast-1.console.aws.amazon.com/ec2/home?region=ap-northeast-1#LimitsCalculator
※外国は24時間対応しているそうなので、英語設定を行い、英語で申請を出すと早く申請が降りる

改めてインスタンス作成を行う。

ssh接続

ターミナルにssh接続コマンドを入力する
ssh -i <pemファイルのアドレス> ubuntu@パブリック DNS(ec2-○○○.com)

pytorchの環境に入る
source activate pytorch_p36

jupyter notebook設定

jupyter notebookにパスワードを設定する
jupyter notebook password

パスワードは下記jsonファイルに保存されているのでコピーする
less ./.jupyter/jupyter_notebook_config.json

各種設定を※pyファイルに記載する
vi ./.jupyter/jupyter_notebook_config.py

/.jupyter/jupyter_notebook_config.py
c = get_config()
c.NotebookApp.ip = '0.0.0.0'
c.NotebookApp.open_browser = False
# 先ほどコピーしたhash関数で生成したパスワード(sha1:###)は以下に記載する
c.NotebookApp.password = 'コピーしたパスワード' 
c.NotebookApp.port=8888

いざ、jupyter notebookを開く
jupyter notebook
http:<アドレス>:8888で起動

起動しない

理由はインスタンス作成時にセキュリティーグループの設定でルールの追加を行っていないからだった

EC2のページの左からセキュリティーグループを選択
→設定しているセキュリティーグループを選択
→アクションを選択し、インバウンドルールを編集する

○カスタムTCP TCP 8888
を追加する(今回はSHH,カスタムTCPともにソースはマイIPを選択した)

そして、もう一度
jupyter notebook

http:<アドレス>:8888で起動

開かない...

原因は、アドレスにプライベートIPを記載していたからだった
パブリックIPを記載し、もう一度

成功

パスワードを入力し、問題なくjupyter notebookを起動することが出来た。

以上

<追記>
確認していないが、下記でローカルに繋げると思う。
ssh -L 8888:localhost:8888 ~
こうすると、サーバーのパブリックIPで接続していたところが、localで接続できるようになる
http://<サーバーアドレス>:8888 → http://localhost:8888

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