XD blog

blog page

remote


2014-11-09 Remote Notebook with Azure

For my teachings, I installed a notebook server on a virtual machine on Azure. All the students will be able to connect the same login (the multi-user configuration is part of the roadmap). The students will not have to install the notebooks by themselves. They will be able to see what other students users do. Here are the steps I followed.

Step 1: create the virtual machine with Azure

I won't detail that, it is pretty straight forward. Just follow the tutorial Create a Virtual Machine Running Windows. I chose a Windows Server. The number of cores must depend on the number of users. I assume all students are not going to access the notebook at the same time except during the lectures. I chose eight cores. I might modify this post in case it is not enough.

Step 2: install Python (latest version - 3.4 today)

I chose the distribution Anaconda 3.4 64bit. This distribution is the most up to date (Python 3.4) and it contains the necessary modules to access a Linux server with a SSH connection (module paramiko). I did not change the default options. For my teachings, you also need to install (with pip):

Step 3: allow connection to the machine

The setup follows the instructions described at IPython Notebook on Azure (French: IPython Notebook sur Azure). I summarize the steps I followed (+ one change in bolded text):

Step 4: install OpenSSL

OpenSSL is not installed on Windows. I did it on c:\OpenSSL. This path will appear later.

Step 5: create an IPython profile for the server

rem for the regular installation
rem cd c:\Python34\Script
cd C:\Anaconda3\Scripts
ipython profile create studentsrv

2015/09/04 I updated to Jupyter 4.0 which does not work the same way. You can create a profile the same way or just do:

jupyter-notebook --generate-config

It just creates a config file, it is better to rename it just after.

Step 6: create a certificate

The command line described in the post mentioned in the previous step does not work unless the config file is specified (see openssl error in reading openssl.conf file). From a command line, execute:

set PATH=%PATH%;c:\OpenSSL\bin
cd %USERPROFILE%\.ipython\profile_studentsrv
openssl req -config C:\OpenSSL\bin\openssl.cfg -x509 -days 365 -newkey rsa:1024 -keyout notebooksrv.key -nodes -out notebooksrv.crt

Step 7: create a password

Create a password for the notebook. The password is encrypted.

rem for the regular installation
rem cd c:\Python34\Script
cd C:\Anaconda3\Scripts
python -c "import IPython;print (IPython.lib.passwd())"

Step 8: edit the configuration for the notebook

It is almost finished, we just need to update the configuration for the notebook server with all the necessary details. Don't forget to replace [user] by your username.

c = get_config()

c.IPKernelApp.pylab = 'inline'
c.NotebookApp.certfile = r'C:\Users\[user]\.ipython\profile_studentsrv\notebooksrv.crt'
c.NotebookApp.keyfile = r'C:\Users\[user]\.ipython\profile_studentsrv\notebooksrv.key'
c.NotebookApp.password = 'sha1:b86e933199ad:a02e9592e5 etc... '

c.NotebookApp.ip = '*'
c.NotebookApp.port = 9999
c.NotebookApp.open_browser = False

Step 9: the final shortcut on the desktop

The last thing to do is to launch the notebooks. This is the command I use:

set PATH=%PATH%;c:\OpenSSL\bin
set PATH=%PATH%;C:\Anaconda3;C:\Anaconda3\Scripts
ipython notebook --profile=studentsrv --notebook-dir=c:\notebooks

2015/09/04 The command line changed. If you run it as it is (IPython 2.1 < 4.0)), it tells Unrecognized alias. The new way to launch the notebook is:

set PATH=%PATH%;c:\OpenSSL\bin
set PATH=%PATH%;C:\PythonENSAE;C:\PythonENSAE\Scripts
jupyter-notebook --config=C:\Users\user_name\.ipython\profile_name\ipython_notebook_config2.py --notebook-dir=c:\notebooks2015

It will probably evolve a little bit again as the current is not fully polished.

Step 10: try it

Everything is set up. The url to try is: https://[machinename].cloudapp.net:9999/. The browser will first ask you to approve a certificate it does not recognize. Once it is approved, you will have to enter the password. You can now download a notebook from anywhere (for example from ENSAE Algorithme et Programmation). You can then drag and drop it on the webpage to upload it to the server.

I created a folder for each user but everybody can look at anybody's folder. This server is more a way to do some exercises without installing everything. To work on sensible data, I recommend to follow the steps on your own in order to get your own server.

Step 11: store your notebooks on Azure BLob Storage

It requires to change the notebook configuration as described at: Using a different notebook store.


Xavier Dupré