古い記事
ランダムジャンプ
新しい記事
さくらインターネットの VPS で jupyter notebook を使いたいんだけど、ダダ漏れは嫌なので HTTPS にしたい。
ということで、やってみた手順です。
VPS の登録方法とかの話は割愛。

Sakura VPS Jupyter Notebook HTTPS SSL

ドメインとサーバの設定



Python 環境構築


  • pyenv + anaconda
    sudo yum install gcc zlib-devel bzip2 bzip2-devel readline readline-devel sqlite sqlite-devel openssl openssl-devel git libffi-devel
    git clone https://github.com/pyenv/pyenv.git ~/.pyenv
    echo 'export PATH="$HOME/.pyenv/bin:$PATH"' >> ~/.bash_profile
    echo 'eval "$(pyenv init -)"' >> ~/.bash_profile
    source ~/.bash_profile
    
    pyenv install --list | grep anaconda
    pyenv install anaconda3-2019.10
    
    conda create -n ana3
    conda init bash
    conda activate ana3
    conda deactivate
    
  • 参考:pyenvを用いたpython環境構築手順(CentOS7.1) - Qiita

jupyter notebook


  • 設定ファイル作成とパスワード登録
    jupyter notebook --generate-config
    jupyter notebook password
    
  • HTTPSのための準備
    • "/etc/letsencrypt/live/[ドメイン名]/" にある cert.pem と privkey.pem を $HOME/.jupyter/ にコピー
    • chown などしておく
  • 設定ファイルの編集
    • vi系つらいので Emacs 入れた: "yum install emacs-nox"
    • emacs ~/.jupyter/jupyter_notebook_config.py
      c.NotebookApp.ip = '0.0.0.0'
      c.NotebookApp.open_browser = False
      c.NotebookApp.port = 8888
      c.NotebookApp.certfile = '/home/yto/.jupyter/cert.pem'
      c.NotebookApp.keyfile = '/home/yto/.jupyter/privkey.pem'
      
  • 起動
    • "jupyter notebook" で起動
    • https://[ドメイン名]:8888/ にアクセス
    • 先ほどのパスワードを入力
    • ヨシ!
  • 動かし続ける
    nohup jupyter notebook >> jupyter.log 2>&1 &
    

日本語文字表示


  • 追加作業(4/2)
    sudo yum -y install ipa-gothic-fonts ipa-mincho-fonts ipa-pgothic-fonts ipa-pmincho-fonts
    emacs ~/.pyenv/versions/anaconda3-2019.10/lib/python3.7/site-packages/matplotlib/mpl-data/matplotlibrc
    > font.family         : IPAGothic
    > font.sans-serif     : IPAGothic, DejaVu Sans, Bitstream Vera Sans, Computer Modern Sans Serif, Lucida Grande, ...
    
  • 参考:Python matplotlibで日本語の設定方法
    • 参考ページと少し違うので注意 (s/IPAexGothic/IPAGothic/)
  • 表示例
    Jupyter Notebook Japanese Chars

参考文献