マルチユーザ用 JupyterHub の構築
やりたいこと
- PAM 認証を使ってそれぞれのユーザがサーバ上で Jupyter を使えるようにする
- ユーザの default dir をサーバの root dir にする
- Bash と R の kernel を使えるようにする
- PATH などの環境変数が引き継がれるようにする
- ファイルの作成などがユーザの permission で行われるようにする
Environment
$ lsb_release -a No LSB modules are available. Distributor ID: Ubuntu Description: Ubuntu 18.04.2 LTS Release: 18.04 Codename: bionic
Installation
Nodejs
$ node -v v8.10.0 $ npm -v
- node.js は既に入っていた。npm を isntall する
- 依存関係の問題で、
libssl
などから入れていかなければならなかった- 単純に
apt install -y npm
で install 出来る場合もあると思われる
- 単純に
$ apt update $ apt install -y libssl1.0-dev $ apt install -y nodejs-dev $ apt install -y node-gyp $ apt install -y npm $ npm -v 3.5.2 $ apt autoremove
JupyterHub
jupyter 関係は入っていなかった
$ pip3 list --format=legacy | grep jupyter $ pip3 install jupyterhub $ npm install -g configurable-http-proxy $ pip3 install notebook $ jupyterhub -h $ configurable-http-proxy -h
$ mkdir -p /etc/jupyterhub $ cd jupyterhub --generate-config $ vim jupyterhub_config.py c.Authenticator.whitelist = {"users"} c.JupyterHub.admin_users = {"users"} c.JupyterHub.allow_named_servers = True c.Spawner.notebook_dir = "/" c.Spawner.default_url = "/tree/home/{username}"
c.Spawner.notebook_dir
- WebUI から見えるファイル構造のルート
- WebUI でホームボタンおした時に飛ぶ先
- URL では /tree に対応する
c.Spawner.default_url
- WebUI からアクセスしたときに、最初に表示する URL
起動は、
$ cd /etc/jupyterhub $ sudo -u root jupyterhub
接続する場合、Host マシンの .ssh/config
に下記を追加
LocalForward 8000 localhost:8000
ブラウザから、localhost:8000
にアクセスする
起動時、下記のような error が発生する場合がある
[E 2019-06-21 09:25:03.286 JupyterHub utils:75] Unexpected error connecting to rhelixa-analysis-001:8000 [Errno 22] Invalid argument
これは、/etc/hosts
を設定するで解決する
$ echo "127.0.0.1 $(hostname)" >> /etc/hosts
Kernel
$ pip3 install bash_kernel $ python3 -m bash_kernel.install
- R Kernel
$ R > install.packages('IRkernel') > IRkernel::installspec()
- Kernel の確認は
jupyter-kernelspec list
を使う- 下記の場合、R kernel が実行出来ないため、適切な場所に配置する
$ jupyter-kernelspec list Available kernels: ir /root/.local/share/jupyter/kernels/ir bash /usr/local/share/jupyter/kernels/bash python3 /usr/local/share/jupyter/kernels/python3 $ cp -r /root/.local/share/jupyter/kernels/ir /usr/local/share/jupyter/kernels/ $ jupyter-kernelspec uninstall ir $ jupyter-kernelspec install /usr/local/share/jupyter/kernels/ $ jupyter-kernelspec list Available kernels: bash /usr/local/share/jupyter/kernels/bash ir /usr/local/share/jupyter/kernels/ir python3 /usr/local/share/jupyter/kernels/python3
Service への登録
https://github.com/jupyterhub/jupyterhub/wiki/Run-jupyterhub-as-a-system-service
$ curl -fsSL https://gist.githubusercontent.com/lambdalisue/f01c5a65e81100356379/raw/ecf427429f07a6c2d6c5c42198cc58d4e332b425/jupyterhub > /etc/init.d/jupyterhub $ sed -i -e "s#PATH=/sbin:/usr/sbin:/bin:/usr/bin:/usr/local/bin#PATH=$(echo $PATH)#g" /etc/init.d/jupyterhub $ chmod +x /etc/init.d/jupyterhub $ systemctl daemon-reload $ update-rc.d jupyterhub defaults $ systemctl start jupyterhub $ systemctl status jupyterhub ● jupyterhub.service - LSB: Start jupyterhub Loaded: loaded (/etc/init.d/jupyterhub; generated) Active: active (running) since Fri 2019-06-21 09:41:16 UTC; 2s ago Docs: man:systemd-sysv-generator(8) Process: 7479 ExecStart=/etc/init.d/jupyterhub start (code=exited, status=0/SUCCESS) Tasks: 9 (limit: 4915) CGroup: /system.slice/jupyterhub.service ├─7498 /usr/bin/python3 /usr/local/bin/jupyterhub --config=/etc/jupyterhub/jupyterhub_co └─7505 node /usr/local/bin/configurable-http-proxy --ip --port 8000 --api-ip 127.0.0.1 - $ systemctl enable jupyterhub