JupyterHub: Difference between revisions

From JoBaPedia
Jump to navigation Jump to search
 
(9 intermediate revisions by the same user not shown)
Line 1: Line 1:
= Setup JupyterHub =
= JupyterHub =
 
== Test Current Setup ==
 
Start service (but should already be running) and follow output
sudo systemctl start jupyterhub
sudo systemctl status jupyterhub
sudo journalctl -f -u jupyterhub
 
Open page with valid certificate  https://banzhaf.chickenkiller.com:7000
 
== Setup New Installation ==


* create new user and group jupyterhub and put user in group shadow
* create new user and group jupyterhub and put user in group shadow
Line 13: Line 24:
  . ~/.bashrc
  . ~/.bashrc
  conda update conda
  conda update conda
* install packages  
* install packages (Minimum: jupyter hub, sudospawner and lab. Recommended: language server, c++ kernel and other useful stuff...)
  conda install -c conda-forge jupyterhub jupyterlab sudospawner opencv pandas matplotlib
  conda install -c conda-forge jupyterhub jupyterlab jupyterlab-lsp python-lsp-server sudospawner xeus-cling opencv pandas matplotlib
* configure jupyterhub
* configure jupyterhub
  jupyterhub --generate-config -f jupyterhub_config.py
  jupyterhub --generate-config -f jupyterhub_config.py
Line 21: Line 32:
  jupyterhub --JupyterHub.spawner_class=sudospawner.SudoSpawner
  jupyterhub --JupyterHub.spawner_class=sudospawner.SudoSpawner
* login at http://localhost:7000
* login at http://localhost:7000
== JupyterHub with SSL ==
super easy if you already have a cert and key (e.g. from letsencrypt): add these two lines to /home/jupyterhub/jupyterhub_config.py
c.JupyterHub.ssl_cert = '/etc/letsencrypt/live/banzhaf.chickenkiller.com/fullchain.pem'
c.JupyterHub.ssl_key = '/etc/letsencrypt/live/banzhaf.chickenkiller.com/privkey.pem'
== JupyterHub as a Service ==
* create script to init conda environment and then start jupyterhub
#!/bin/bash
. ~/.bashrc
exec jupyterhub --JupyterHub.spawner_class=sudospawner.SudoSpawner
* create systemd script /etc/systemd/system/jupyterhub.service
Description=Jupyterhub
[Service]
User=jupyterhub
ExecStart=/home/jupyterhub/jupyterhub.sh
WorkingDirectory=/home/jupyterhub
[Install]
WantedBy=multi-user.target
* Install own kernel with conda environment
** start terminal and create conda environment as usual (or list existing envs to choose from)
** activate the conda environment and make sure ipykernel module is installed
** register new kernel
myenv=my-new-env
conda activate "$myenv"
python -m ipykernel install --user --name "$myenv" --display-name "Python ($myenv)"
** reload hub page and start Launcher (+) to see the new kernel

Latest revision as of 16:14, 6 April 2022

JupyterHub

Test Current Setup

Start service (but should already be running) and follow output

sudo systemctl start jupyterhub
sudo systemctl status jupyterhub
sudo journalctl -f -u jupyterhub

Open page with valid certificate https://banzhaf.chickenkiller.com:7000

Setup New Installation

  • create new user and group jupyterhub and put user in group shadow
  • allow sudo for members of group. Create /etc/sudoers.d/jupyterhub
Cmnd_Alias JUPYTER_CMD = /home/jupyterhub/miniconda3/bin/sudospawner
jupyterhub ALL=(%jupyterhub) NOPASSWD:JUPYTER_CMD
  • install conda for that user
script=Miniconda3-latest-Linux-x86_64.sh
wget "https://repo.anaconda.com/miniconda/$script"
chmod +x "$script"
"./$script" -b
~/miniconda3/bin/conda init bash
. ~/.bashrc
conda update conda
  • install packages (Minimum: jupyter hub, sudospawner and lab. Recommended: language server, c++ kernel and other useful stuff...)
conda install -c conda-forge jupyterhub jupyterlab jupyterlab-lsp python-lsp-server sudospawner xeus-cling opencv pandas matplotlib
  • configure jupyterhub
jupyterhub --generate-config -f jupyterhub_config.py
add line "c.JupyterHub.bind_url = 'http://:7000'" to config file 
  • start the hub
jupyterhub --JupyterHub.spawner_class=sudospawner.SudoSpawner

JupyterHub with SSL

super easy if you already have a cert and key (e.g. from letsencrypt): add these two lines to /home/jupyterhub/jupyterhub_config.py

c.JupyterHub.ssl_cert = '/etc/letsencrypt/live/banzhaf.chickenkiller.com/fullchain.pem'
c.JupyterHub.ssl_key = '/etc/letsencrypt/live/banzhaf.chickenkiller.com/privkey.pem'

JupyterHub as a Service

  • create script to init conda environment and then start jupyterhub
#!/bin/bash
. ~/.bashrc
exec jupyterhub --JupyterHub.spawner_class=sudospawner.SudoSpawner
  • create systemd script /etc/systemd/system/jupyterhub.service
Description=Jupyterhub

[Service]
User=jupyterhub
ExecStart=/home/jupyterhub/jupyterhub.sh
WorkingDirectory=/home/jupyterhub

[Install]
WantedBy=multi-user.target
  • Install own kernel with conda environment
    • start terminal and create conda environment as usual (or list existing envs to choose from)
    • activate the conda environment and make sure ipykernel module is installed
    • register new kernel
myenv=my-new-env
conda activate "$myenv"
python -m ipykernel install --user --name "$myenv" --display-name "Python ($myenv)"
    • reload hub page and start Launcher (+) to see the new kernel