LoginSignup
0
0

More than 5 years have passed since last update.

Microsoft Azure VM CentOS上でjupyter serverを立ち上げ、ローカルからアクセス

Last updated at Posted at 2018-10-08

製品をLinux上で開発しているため、手元のMacではなくLinux環境で検証や開発をしたいが、jupyterで可視化、トライアンドエラーしたいというモチベーションで実践した。
(結局jupyterは製品に組み込む時に面倒なので使うのをやめた)

Azure VM CentOS

jupyterのインストール

sudo pip3 install jupyter
mkdir ~/.jupyter

通信ssl化

cd ~/.jupyter/
openssl req -x509 -nodes -newkey rsa:2048 -keyout mycert.key -out mycert.pem

パスワードハッシュ文字の取得

ipython3
from notebook.auth import passwd
passwd()
ローカルからのログイン用のパスワードを入力
'入力したパスワードのハッシュ文字が表示される'--->①

jupyter notebookの設定ファイル作成

touch ~/.jupyter/jupyter_notebook_config.py
vi ~/.jupyter/jupyter_notebook_config.py

jupyter_notebook_config.pyの設定内容

c = get_config()
c.NotebookApp.ip = '*'
c.NotebookApp.open_browser = False
c.NotebookApp.port = 18888
c.NotebookApp.password = u'①で表示されたパスワードのハッシュ文字'
c.NotebookApp.certfile = u'/home/【自分のホームディレクトリ】/.jupyter/mycert.pem'
c.NotebookApp.keyfile = u'/home/【自分のホームディレクトリ】/.jupyter/mycert.key'

Azureの設定

azureのリソースグループの設定で18888ポートを開放

リソースグループ -> 自分のリソースグループ -> ネットワークセキュリティグループ -> 受信セキュリティ規則 -> 追加
- 宛先ポート範囲:18888
- プロトコル:TCP
- 他はデフォルトで、名前はjupyter等わかりやすい物に。

運用

サーバ起動(Azure VM)

jupyter notebook &

起動時のカレントディレクトリが、クライアント起動時のホームディレクトリとなる
Azureからsshを切ってもjupyterを継続したい場合は以下。

nohup jupyter notebook > /dev/null 2>&1 &

ローカルのブラウザからアクセス

https://[azure vm ipアドレス]:18888

サーバ停止

fg -> Ctrl+c -> y

0
0
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
0