Skip to content

Instantly share code, notes, and snippets.

@jlandercy
Forked from prerakmody/jupyterhub_installation.md
Created November 13, 2020 08:17
Show Gist options
  • Save jlandercy/62005ec66e9c26e183a3055da9f18456 to your computer and use it in GitHub Desktop.
Save jlandercy/62005ec66e9c26e183a3055da9f18456 to your computer and use it in GitHub Desktop.
Jupyter Hub

Installation

  1. Spin up an AWS/Azure/GCP machine (Ubuntu - 16.04)
    • ensure you know how to use the web-interface of these IaaS to open ports for an instance
    • open ports 80, 443, 8000, 8888
  2. Follow this link
  3. Create a dir (.jupyterhub) which shall contain jupyterhub specific files
    • mkdir .jupyterhub
    • cd .jupyterhub
    • jupyterhub --generate-config
    • openssl rand -hex 8 > jupyterhub_cookie_secret
  4. Config file edits
    • vim jupyterhub_config.py
    • c.Authenticator.admin_users = {'<username>'}
      c.JupyterHub.admin_access = True
      
      c.JupyterHub.cookie_secret_file = 'jupyterhub_cookie_secret'
      
      c.JupyterHub.logo_file = '/home/play/tmp/playment_logo_32x32.png'
      
      origin = '*'
      c.JupyterHub.tornado_settings = {
          'headers': {
            'Access-Control-Allow-Origin': origin,
         },
      }
      c.Spawner.args = ['--NotebookApp.allow_origin={0}'.format(origin)]
      
  5. Server Run
  • sudo jupyterhub to check if the server runs fine. Default ip=127.0.0.1 and port=8000
  • OR sudo jupyterhub --ip=127.0.0.1 --port=<port_number>
  1. Open your browser
    • type <instance_ip>:8000 in your browser to see if you can access the
    • to get your instance_ip, go to your command line and type curl ipecho.net/plain
  2. One can also setup OAuth
  3. One cal also setup Jupyter extensions
    • sudo jupyter contrib nbextension install --system --symlink --debug
      sudo chmod -R 0777 /usr/local/etc/jupyter/nbconfig
      
    • vim jupyterhub_config.py
      import os
      os.environ['JUPYTER_CONFIG_DIR'] = '/usr/local/etc/jupyter/nbconfig'
      c.Spawner.env_keep.append('JUPYTER_CONFIG_DIR')
      

Setting up network requirements

  1. Install nginx
  2. Open /etc/nginx/sites-enabled/default
  3. Add the following configuration
  • upstream notebook {
    server 127.0.0.1:8000;  #this should be the ip:port where you jupyterhub is running
    }
    
    # redirect http --> https
    server {
        listen 80;
        server_name <domain_name>;
    
        # redirects both www and non-www to https
        return 301 https://<domain_name>$request_uri;
    }
    
    server{
      # listen 80;
      listen 443 ssl;
      server_name <domain_name> <ip>;
    
      ssl_certificate <>.pem; # managed by Certbot
      ssl_certificate_key <>.pem; # managed by Certbot
    
      location / {
            proxy_pass            http://notebook;
            proxy_set_header      Host $host;
      }
    
      location ~ /api/kernels/ {
            proxy_pass            http://notebook;
            proxy_set_header      Host $host;
            # websocket support
            proxy_http_version    1.1;
            proxy_set_header      Upgrade "websocket";
            proxy_set_header      Connection "Upgrade";
            proxy_read_timeout    86400;
        }
      location ~ /terminals/ {
            proxy_pass            http://notebook;
            proxy_set_header      Host $host;
            # websocket support
            proxy_http_version    1.1;
            proxy_set_header      Upgrade "websocket";
            proxy_set_header      Connection "Upgrade";
            proxy_read_timeout    86400;
      }
    }
    
  1. To get credentials follow this link
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment