It shows the simplest way about how to deploy and configure this powerful platform for interactive computing, including deployment, configuration, auto-start on system boot, logs cleaning, and etc.
This article is for Ubuntu.
Installation
The official guideline could be found here.
Install nodejs, npm, jupyterhub, configurable-http-proxy, jupyterlab, notebook
# 1. use [pip]
sudo apt-get install nodejs npm
python3 -m pip install jupyterhub
npm install -g configurable-http-proxy
# 2. needed if running the notebook servers in the same environment
python3 -m pip install jupyterlab notebook
# 3. install jupyterhub-idle-culler
pip install jupyterhub-idle-culler
BashTest your installation:
jupyterhub -h
configurable-http-proxy -h
BashConfiguration
Official document could be found here.
Generate the config file with below command. It will auto generate jupyterhub_config.py:
jupyterhub --generate-config
Bash# Below settings are for reference only
c = get_config() #noqa
# Proxy
c.ConfigurableHTTPProxy.should_start = True
c.ConfigurableHTTPProxy.api_url = 'http://localhost:5432'
# IP & Port
c.JupyterHub.ip = '0.0.0.0'
c.JupyterHub.port = 8050
c.PAMAuthenticator.encoding = 'utf8'
# Admin user
c.Authenticator.admin_users = {'root'}
c.Authenticator.allow_all = True
# Admin user has the right to log in to each computer as another user for debugging purposes.
c.JupyterHub.admin_access = True
# Avoid manually creating all users before starting the service.
c.LocalAuthenticator.create_system_users = True
c.JupyterHub.authenticator_class = 'jupyterhub.auth.PAMAuthenticator'
# working directory (where .ipynb is saved)
c.Spawner.notebook_dir = '/opt/jupyterhubfile'
c.Spawner.default_url = '/lab'
c.Spawner.args = ['--allow-root']
c.Spawner.cmd = ['jupyter-labhub']
c.PAMAuthenticator.service = 'sshd'
c.PAMAuthenticator.open_sessions = False
c.JupyterHub.services = [
{
'name': 'idle-culler',
'command': ['python3', '-m', 'jupyterhub_idle_culler', '--timeout=3600'],
'admin':True
}
]Python
PythonStart Jupyterhub Service
# Start with customized config
jupyterhub -f /path/to/jupyterhub_config.py
BashAuto-start when system boot
Create a systemctl config file to launch JupyterHub:
vi /etc/systemd/system/jupyterhub.service
Bash[Unit]
Description=JupyterHub
After=syslog.target network.target
[Service]
User=root
Group=root
Environment="PATH=/opt/anaconda3/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/bin"
ExecStart=/opt/anaconda3/bin/jupyterhub -f /opt/anaconda3/lib/python3.12/site-packages/jupyterhub/jupyterhub_config.py
[Install]
WantedBy=multi-user.target
Bash- Description: Description of the service.
- After: Specifies that JupyterHub should start after syslog and network services have started.
- User: Specifies that JupyterHub should run as the root user.
- Environment: Sets environment variables to ensure that PATH includes the path to Anaconda
- ExecStart: Specifies the path to the startup script.
- WantedBy: Specifies that the service should be loaded when the multi-user target is started.
Reload systemd service:
sudo systemctl daemon-reload
BashTry to start Jupyterhub service with systemctl:
sudo systemctl start jupyterhub
BashCheck the service status:
sudo systemctl status jupyterhub
BashEnable the config when system boot if the service is running normally:
sudo systemctl enable jupyterhub
BashConfig Journal
To avoid generating lots of logs, we can modify Journal settings.
Edit journal config file:
vi /etc/systemd/journald.conf
BashUncomment and modify below settings:
# Limit the disk space used by log files
SystemMaxUse=100M
# Limit the maximum size of individual log files
SystemMaxFileSize=50M
# Limit the maximum number of log files
SystemMaxFiles=10
# Set the maximum retention period for logs
MaxRetentionSec=1month
BashSave the settings and restart service:
sudo systemctl restart systemd-journald
BashCOMMON COMMAND
# Check Jupyterhub log
journalctl -u jupyterhub
# Check log usage
journal --disk-usage
BashNow, please enjoy Jupyterhub!