Jupyter
From FarmShare
(→Create virtual terminal: added example jupyter noteboko start output) |
m (→Create virtual terminal: formatting) |
||
Line 80: | Line 80: | ||
<pre> | <pre> | ||
IMPORTANT: This Jupyter notebook's session port is 9876 | IMPORTANT: This Jupyter notebook's session port is 9876 | ||
+ | |||
[I 17:23:59.661 NotebookApp] Loading IPython parallel extension | [I 17:23:59.661 NotebookApp] Loading IPython parallel extension | ||
[I 17:23:59.668 NotebookApp] Serving notebooks from local directory: /afs/ir.stanford.edu/users/j/a/jane | [I 17:23:59.668 NotebookApp] Serving notebooks from local directory: /afs/ir.stanford.edu/users/j/a/jane |
Revision as of 18:30, 28 December 2016
Contents |
Introduction
Project Jupyter evolved out of the IPython project (specifically the IPython notebook) with the goal to provide an interactive, web-browser driven, language-independent programming environment. Jupyter notebooks can be deployed on the FarmShare servers to enable an accessible, powerful, and persistent computational platform.
Features
At the end of this guide, the resulting Jupyter notebook will support:
- python and matlab programming languages
- an encrypted, token protected, and web-browser enabled programming environment
- persistence of the Jupyter notebook server environment for one week (the maximum duration of Stanford Kerberos tickets) with simple service renewal
- file/data storage on the Stanford AFS servers (5GB user quota, Stanford-wide, automatic backups)
- shared file/data storage to Class Disk AFS Space
- easy deployment on any of the Stanford FarmShare systems
Overview
The guide consists of three sections: installation, Jupyter notebook server management, and client connection. In typical usage (i.e., once installation is complete and the Jupyter notebook server is running), only the client connection steps are necessary at every use.
Installation
Jupyter setup is best performed via the Linux console. This guide will be mostly step-by-step, but general familiarity with Linux is helpful. Useful tutorials are available as a free book, online tutorial, or video series.
SSH provides an encrypted remote shell into another system and is the primary way that Jupyter will be installed and accessed.
SSH into one of the farmshare computers. The corn cluster (i.e., corn.stanford.edu) is a good choice. Windows does not come with an SSH client, but putty is a a free and lightweight SSH client for Windows. Mac and Linux have ssh clients accessible via the terminal.
Bind to Jupyter virtual environment
corn99:~> bash jane@corn99:~$ source /afs/ir.stanford.edu/group/bil/env/jupyter/bin/activate (jupyter)jane@corn99:~$
These two commands switch the shell to bash and then update the environment to use a pre-built Jupyter installation. The prompt should have the (jupyter)
prefix if the environment change is successful.
This Jupyter environment has the following packages installed:
bokeh ipyparallel ipython jupyter jupyter_contrib_nbextensions matplotlib numpy pandas scipy seaborn statsmodels sympy
Setup encryption and default configuration
(jupyter)jane@corn99:~$ /afs/ir.stanford.edu/group/bil/env/scripts/jupyter_config_wrapper
This command calls a script that will create encryption keys for the Jupyter notebook and configure the jupyter config file to use these newly created keys. Note, this will modify existing Jupyter notebook config files (if they exist), but will not overwrite any parameters that have changed from their default values.
Installation is complete after this step is successful. Log out of FarmShare.
Jupyter notebook server
Jupyter notebook will be run within a persistent virtual terminal so it can stay running even after the user has logged out of FarmShare.
Create virtual terminal
This only needs to be performed once per FarmShare system (and after every server reboot).
SSH into a FarmShare system (e.g. corn). Make a note of exactly which corn server entered (e.g., corn14, corn22, etc).
corn99:~$ pagsh sh-4.3$ kinit; aklog Password for jane@stanford.edu: sh-4.3$ tmux (new blank terminal appears) corn99:~$ bash jane@corn99:~$ /afs/ir.stanford.edu/group/bil/env/scripts/keep_kerberos_afs jane@corn99:~$ export KRB5CCNAME=FILE:/tmp/.krb5_jane.tgt jane@corn99:~$ source /afs/ir.stanford.edu/group/bil/env/jupyter/bin/activate (jupyter)jane@corn99:~$ /afs/ir.stanford.edu/group/bil/env/scripts/jupyter_start
Substitute sunetid for jane
in the export
line (as instructed by the keep_cerebus_afs
command). If done correctly, the output of this command will be
IMPORTANT: This Jupyter notebook's session port is 9876 [I 17:23:59.661 NotebookApp] Loading IPython parallel extension [I 17:23:59.668 NotebookApp] Serving notebooks from local directory: /afs/ir.stanford.edu/users/j/a/jane [I 17:23:59.668 NotebookApp] 0 active kernels [I 17:23:59.668 NotebookApp] The Jupyter Notebook is running at: https://localhost:9876/?token=ba682763f27d8e2d59862badef28b0eaecb552529933176e [I 17:23:59.668 NotebookApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation). [C 17:23:59.671 NotebookApp] Copy/paste this URL into your browser when you connect for the first time, to login with a token: https://localhost:9876/?token=ba682763f27d8e2d59862badef28b0eaecb552529933176e
Copy the https://localhos...
URL and save it for subsequent use. Also note the TCP port that the Jupyter notebook is listening on. Use Ctrl+b
then d
to detach from tmux. Logout of FarmShare.
Ctrl+b d (detaches tmux) sh-4.3$ exit corn99:~> logout
Renewing virtual terminal
The virtual terminal created by the above instructions will persist on the FarmShare server for one week, after which its Kerberos tickets will expire and the Jupyter notebook will no longer function. To restore the notebook after this time, SSH into the same FarmShare system used to create the virtual terminal.
corn99:~$ tmux attach -d Ctrl+c then y (to kill the defunct but running Jupyter notebook) (jupyter)jane@corn99:~$ kinit; aklog Password for jane@stanford.edu: (jupyter)jane@corn99:~$ /afs/ir.stanford.edu/group/bil/env/scripts/jupyter_start
This will extend the terminal's credentials for another week. Again, copy the https://localhos...
URL and note the port, as these replace the prior URL and port from the earlier Jupyter notebook session.
The jupyter_start
script accepts an optional argument, indicating which port to connect to (e.g., jupyter_start 9876). This is useful for connecting to the same port every time instead of a randomized port.
Client connection
Create SSH tunnel
Once the Jupyter notebook server is running, it is ready to accept client connections. For security, it only accepts connections from localhost (i.e., connections originating from the FarmShare system itself). Local connections can be created remotely through SSH tunnels. SSH into the same FarmShare system that the Jupyter notebook server virtual terminal was created on (e.g., corn14, corn22, etc) by using the server's FQDN (e.g., corn14.stanford.edu) with a local port tunnel to the TCP port that the server is listening on.
In Mac/Linux, setup the SSH tunnel in a terminal.
$ ssh jane@corn99.stanford.edu -L 9999:localhost:9999
substituting in the appropriate sunetid for jane
, the appropriate FarmShare server hostname for corn99
, and the appropriate TCP port for 9999
. Windows users can setup an SSH local tunnel using menu options in putty
Once the ssh tunnel has been established, paste the https://localhos...
URL provided from the jupyter_start
script into a web browser to connect to the notebook home page. If this URL is misplaced, use tmux attach -d
to bring up the virtual terminal and copy the URL again. Since the encryption keys were self-signed, the browser will warn about an insecure connection, but disregard these and continue/proceed past them.