Skip to content

Instantly share code, notes, and snippets.

@koldunovn
Last active August 9, 2018 10:42
Show Gist options
  • Save koldunovn/ab4422e6270ba1425be1f56b4f1f0f95 to your computer and use it in GitHub Desktop.
Save koldunovn/ab4422e6270ba1425be1f56b4f1f0f95 to your computer and use it in GitHub Desktop.
## How to connect to Jupyter Notebook on DKRZ or Ollie

How to connect to Jupyter Notebook on DKRZ or Ollie

Ollie

If you are in the AWI network (for example through VPN), the easiest way to run jupyter notebook is to login on ollie and execute:

module load python3/3.6.3-intel2018
module load gdal/2.2.3
jupyter notebook password

set the password, then

jupyter notebook --no-browser --ip="0.0.0.0"

It will give you the line looking like:

The Jupyter Notebook is running at: http://0.0.0.0:8888/

You have to change 0.0.0.0 to ollie1 or ollie2 and past it in your browser.

However this will not work on DKRZ.

Ollie and DKRZ

The following example will work for DKRZ and for ollie if the simple ollie way did not work for you.

What we have to do is to create an SSH tunnel to the remote mashine that will map port on the remote mashine to the port on your computer.

Prerequisite to it is that you have to run jupyter notebook on the remote host with certain settings, in particular we will define specific port to run the notebook on, will run the notebook without the browser and also will protect it with the pasword. Please follow the steps below. I will use DKRZ as an example, for olli everything will be the same. More details you can find here and here

Connect to misttral (use you DKRZ account):

ssh -Y a270???@mistral.dkrz.de

load python module with jupyter notebook included. At the time of writing on DKRZ it is

module load anaconda3/4.3.1-python-3.6.0

Generate jupyter config:

jupyter notebook --generate-config

The .jupyter/jupyter_notebook_config.py file will be created.

Next step is to create a password. The easy way with just executing jupyter notebook password does not work on DKRZ for watever reason, but you might have more luck. The old school method is to generate hash for your password is to run ipython and do the following:

In [1]: from IPython.lib import passwd

In [2]: passwd()
Enter password:
Verify password:
Out[2]: 'sha1:1e63ffad66c4:c529288f9979bf54a1277l7d25eb4d5849e1c695'

Remember Save the hash somewere, we will have to enter it to the jupyter configuration file.

Now open your .jupyter/jupyter_notebook_config.py and insert the following lines at the top of the file:

# Configuration file for jupyter-notebook.
c = get_config()
# Notebook config
c.NotebookApp.ip = 'localhost'
c.NotebookApp.open_browser = False
c.NotebookApp.password = u'sha1:1e63ffad66c4:c529288f9979bf54a1277l7d25eb4d5849e1c695'
# It is a good idea to put it on a known, fixed port
c.NotebookApp.port = ?????

Of course you should use your hash for the password and select the port. which will be a number in the range of (1024—49151). I explicitly do not put an example port here, since if several users will try to use the same port it will cause troubles. So in the following our example port number will be ????? that you have to replace with your port number.

This is it for the server side setup. Now when you run jupyter notebook on the server it will use .jupyter/jupyter_notebook_config.py with your configuration (you can setup a lot of additional things in there).

Now we have to connect to the server from our computer in a "spetial way", using SSH port forwarding in a way that the port on our machine is mapped to the port on the server where jupyter will be working. You ssh login should look like this:

ssh -L ?????:localhost:????? a270???@mistralpp.dkrz.de

You replace ????? by your port number and a270??? by your user account. After the login you can execute:

module load anaconda3/4.3.1-python-3.6.0
jupyter notebook

on the server. Be patient, DKRZ is unfamous for VERY slow python startup times, so it might take one or two minutes before the notebook will start. You have to see something like this

[I NotebookApp] Serving notebooks from local directory: /mnt/lustre01/pf/a/a270???
[I NotebookApp] 0 active kernels
[I NotebookApp] The Jupyter Notebook is running at:
[I NotebookApp] http://localhost:?????/
[I NotebookApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).

Copy the http://localhost:?????/ part in your browser and endjoy :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment