Running Jupyter Notebook on a server using your client browser

Running Jupyter Notebook using X-forwarding on a server can be sluggish and unresponsive. Here is how you can use your local browser but still run your code using the servers resources. 

Image may contain: Orange, Font, Material property, Circle, Logo.

What is Jupyter Notebook?

Jupyter Notebook and its flexible interface extends the notebook beyond code to visualization, multimedia, collaboration, and more. In addition to running your code, it stores code and output, together with markdown notes, in an editable document called a notebook. When you save it, this is sent from your browser to the Jupyter server, which saves it on disk as a JSON file with a .ipynb extension.

https://docs.jupyter.org/

Getting started

Log on to the server and start it up.

On the client, connect to the server using ssh. We will use mimi.uio.no in this example.

(Tip: To make ssh connections easier, you can set yourself up with ssh keys)

ssh username@mimi.uio.no 

Load the Anaconda module:

$ module load Anaconda3/2022.05

First, check if you already have any running notebooks on the server:

$ jupyter notebook list

If you do, paste the link from the output in your local browser and continue your work. 

If not, start a new jupyter notebook:

$ jupyter notebook --no-browser

[W 14:23:12.075 NotebookApp] Loading JupyterLab as a classic notebook (v6) extension.
[C 14:23:12.076 NotebookApp] You must use Jupyter Server v1 to load JupyterLab as notebook extension. You have v2.3.0 installed.
    You can fix this by executing:
        pip install -U "jupyter-server<2.0.0"
[I 14:23:12.078 NotebookApp] Serving notebooks from local directory: /uio/kant/geo-adm-u1/kjetba
[I 14:23:12.078 NotebookApp] Jupyter Notebook 6.5.2 is running at:
[I 14:23:12.078 NotebookApp] http://localhost:8888/?token=d9ed1ac41c33137a65d6ef6db7c4a379f63dca7311198547
[I 14:23:12.078 NotebookApp]  or http://127.0.0.1:8888/?token=d9ed1ac41c33137a65d6ef6db7c4a379f63dca7311198547

At the bottom of the output is where you will find the URL you need to use with your client browser in the last step. Make note of the port number assigned. In this example 8888

Now we need to set up a dedicated ssh tunnel for it to work using the port number assigned. Open another terminal and type in:

ssh -L 8888:localhost:8888 username@mimi.uio.no

Then open the URL in your favorite client browser. In this example: 

http://localhost:8888/?token=d9ed1ac41c33137a65d6ef6db7c4a379f63dca7311198547

 

By Kjetil Bakke
Published Mar. 22, 2023 4:10 PM - Last modified Mar. 23, 2023 2:38 PM