§2024-12-27

試作機器: nvidiaSdk. a x86_64, running ubuntu 24.04

  1. put under conda control
(base) alexlai@NvidiaSdk:~$ conda activate RStudio
(RStudio) alexlai@NvidiaSdk:~$
  1. install jupyterhub notebook configurable-http-proxy
$ conda install conda-forge::jupyterhub ( or a simple jupyterhub-base
$ conda install conda-forge::notebook
$ conda install conda-forge::configurable-http-proxy
$ conda install conda-forge::sqlite
  1. Generate a default JupyterHub configuration file:
RStudio) alexlai@NvidiaSdk:~$ mkdir ~/jupyterhub && cd $_
$ jupyterhub --generate-config
$ cp -v jupyterhub_config.py jupyterhub_config.py.backup
  1. exit the jupyterhub_config.py file to customize settings.

For example, set the port and configure the user whitelist or admin users:

c.JupyterHub.bind_url = 'http://:8000' c.Authenticator.allowed_users = {'alexlai', 'rstudio-server'} c.Authenticator.allowed_users = None # allow all valid user c.Authenticator.admin_users = {'alexlai'}

  1. Start JupyterHub

Run the following command to start JupyterHub:

jupyterhub By default, it will be accessible at http://localhost:8000. Users can log in using their system credentials.

Step 7: Optional - Enable HTTPS For production environments, it’s recommended to enable HTTPS by obtaining an SSL certificate. Update the jupyterhub_config.py file:

c.JupyterHub.ssl_cert = '/path/to/ssl-cert.pem' c.JupyterHub.ssl_key = '/path/to/ssl-key.pem' Restart JupyterHub to apply changes.

Additional Notes

$ cat  /home/rstudio-server/anaconda3/envs/RStudio/bin/jupyterhub
#!/home/rstudio-server/anaconda3/envs/RStudio/bin/python3.13
# -*- coding: utf-8 -*-
import re
import sys

from jupyterhub.app import main

if __name__ == '__main__':
    sys.argv[0] = re.sub(r'(-script\.pyw?|\.exe)?$', '', sys.argv[0])
    sys.exit(main())

and

$ ldd `which python` |grep pam  --> is blank
import pam

# Authenticate using PAM
username = 'alexlai'
password = 'your_password_here'

try:
    pam.authenticate(username, password)
    print("Authentication successful!")
except pam.error:
    print("Authentication failed.")
$ python test_python_pam_enabled.py 
Traceback (most recent call last):
  File "/home/alexlai/jupyterhub/test_python_pam_enabled.py", line 1, in <module>
    import pam
ModuleNotFoundError: No module named 'pam'
$ pip install python-pam
$  pip install python-pam
Collecting python-pam
  Downloading python_pam-2.0.2-py3-none-any.whl.metadata (3.5 kB)
Downloading python_pam-2.0.2-py3-none-any.whl (10 kB)
Installing collected packages: python-pam
Successfully installed python-pam-2.0.2
(RStudio) alexlai@NvidiaSdk:~/jupyterhub$ python test_python_pam_enabled.py 
Authentication successful!

For advanced authentication, you can use OAuth, LDAP, or other methods by installing and configuring a custom authenticator (e.g., GitHub or Google OAuth). For scalability, consider deploying JupyterHub using Docker or Kubernetes with the Zero to JupyterHub guide. Let me know if you'd like help with any specific part of this process!


The configurable-http-proxy (CHP) plays a crucial role in JupyterHub as its reverse proxy. Here's what it does and why it is important:

Role of configurable-http-proxy in JupyterHub Routing Requests:

CHP acts as a middleman between users and the various services running within JupyterHub. It routes incoming HTTP requests to the appropriate backend service, such as: The JupyterHub server itself (for authentication and management). User-specific Jupyter notebook servers. Dynamic Proxying:

JupyterHub dynamically starts and stops single-user notebook servers for each logged-in user. CHP keeps track of these servers and ensures that requests for a specific user are routed to their dedicated notebook server. Centralized Access Point:

All user requests, whether they are for logging in or accessing their notebook server, go through CHP, providing a centralized access point. This simplifies deployment and management, as it abstracts the complexity of managing multiple services behind a single interface. TLS Termination (Optional):

CHP can handle SSL/TLS termination if HTTPS is enabled directly on it. Alternatively, a separate HTTPS reverse proxy (e.g., Nginx or Traefik) can be used in front of CHP. Configurable:

As its name suggests, CHP is highly configurable. Administrators can tweak its settings to suit their deployment needs, such as custom routes or advanced load balancing. How It Works in Practice JupyterHub Core:

The main JupyterHub server manages users, authentication, and spawning single-user servers. Single-User Notebook Servers:

Each user gets their own Jupyter notebook server running on a unique port or address. CHP Functionality:

When a user logs in: The main JupyterHub server tells CHP to route requests for that user to their notebook server. CHP maintains a mapping of user sessions and routes: php Copy code /user/ -> http://<notebook_server_address>: If a user logs out or their server is stopped, CHP removes the corresponding route. Why JupyterHub Uses CHP Dynamic Nature: JupyterHub's multi-user environment requires starting and stopping user notebook servers on-demand. CHP handles these dynamic routing requirements efficiently. Scalability: CHP can manage many simultaneous connections, making it suitable for small-scale and large-scale deployments. Customization: Its flexibility allows it to be configured for various deployment architectures, including those involving Docker or Kubernetes. Commands and Configuration You can manually run and test configurable-http-proxy with:

bash Copy code configurable-http-proxy --port 8000 --default-target http://127.0.0.1:8081 This sets it up to listen on port 8000 and forward all requests to a backend service running on port 8081.

In JupyterHub, CHP is managed automatically by the hub process, so you typically don't need to interact with it directly unless troubleshooting or customizing your setup.