[CENTOS] Build Jupyter Hub

Build Jupyter Hub

What are you using, the Python coding environment? I think there are surprisingly many people who call it Jupyter Notebook. Jupyter Notebook is a coding environment used in a web browser, and by using a plug-in, it can be used as a coding environment for Java, R, etc. in addition to Python.

User management is not possible with Jupyter Notebook alone, which is inconvenient when developing in groups. With JupyterHub, you can add a user authentication interface to Jupyter Notebook, so I will show you how to build it.

※ JupyterHub http://jupyterhub.readthedocs.io/en/latest/index.html

environment

The construction environment introduced this time is as follows.

Preset

First, let's install Anaconda 4.3.0 in advance.

Download Anaconda's installation shell for Linux.

#From now on, operate as the root user, but actually use a user that can be used.
sudo su -
cd ~
wget https://repo.continuum.io/archive/Anaconda3-4.2.0-Linux-x86_64.sh

Install Anaconda. You will be asked variously during the installation, but basically yes is fine.

However, there is one caveat. The installation directory should be / opt / anaconda3 / for the time being. The default installation directory is / root / anaconda3 /, which prevents non-root users from using Anaconda. If a non-root user (with or without sudo privileges) uses JupyterHub, install it in a directory accessible to that user as well.

bash Anaconda3-4.2.0-Linux-x86_64.sh

2017-02-05_1.png

Anaconda is now installed. You don't need to configure Jupyter Notebook, so it's time to install Jupyter Hub.

Install JupyterHub

After installing Anaconda, you can install packages for Anaconda and Python modules with the conda install command. JupyterHub is also installed with conda install.

#Install Jupyter Hub
conda install -c conda-forge jupyterhub
#Install JupyterHub notebook
conda install notebook

You can now install Jupyter Hub and launch Notebook. Next, create a Config file and configure the settings.

Create a JupyterHub Config file

The JupyterHub Config file is generated by the following command.

cd /opt/
jupyterhub --generate-config

A file called jupyterhub_config.py is created like this.

2017-02-05_2.png

JupyterHub settings

JupyterHub allows you to configure various settings such as proxy, TLS certificate, user, administrative user, etc. This time, at a minimum, set only the admin user, user, and user's Notebook directories. Open jupyterhub_config.py in an editor.

vi jupyterhub_config.py

Change the following settings.

First is the Notebook directory. Create a ~ / notebook / directory under each user's home directory and make it the Notebook directory.

## Path to the notebook directory for the single-user server.
#
#  The user sees a file listing of this directory when the notebook interface is
#  started. The current interface does not easily allow browsing beyond the
#  subdirectories in this directory's tree.
#
#  `~` will be expanded to the home directory of the user, and {username} will be
#  replaced with the name of the user.
#
#  Note that this does *not* prevent users from accessing files outside of this
#  path! They can do so with many other means.
#c.Spawner.notebook_dir = ''
#Add the following
c.Spawner.notebook_dir = '~/notebook'

Next is the user of Jupyter Hub. Set this as a Whitelist.

## Whitelist of usernames that are allowed to log in.
#
#  Use this with supported authenticators to restrict which users can log in.
#  This is an additional whitelist that further restricts users, beyond whatever
#  restrictions the authenticator has in place.
#
#  If empty, does not perform any additional restriction.
#c.Authenticator.whitelist = set()
#Add the following
c.Authenticator.whitelist = {'user01', 'user02'}

Finally, the admin user.

## Set of users that will have admin rights on this JupyterHub.
#
#  Admin users have extra privilages:
#   - Use the admin panel to see list of users logged in
#   - Add / remove users in some authenticators
#   - Restart / halt the hub
#   - Start / stop users' single-user servers
#   - Can access each individual users' single-user server (if configured)
#
#  Admin access should be treated the same way root access is.
#
#  Defaults to an empty set, in which case no user has admin access.
#c.Authenticator.admin_users = set()
#Add the following
c.Authenticator.admin_users = {'user00'}

This completes the minimum settings. See below for other settings. http://jupyterhub.readthedocs.io/en/latest/getting-started.html#configuration

Create a notebook for each user

Create a Notebook for users of the Jupyter Hub.

mkdir -p /home/user01/notebook
chown user01:usergr /home/user01/notebook

Start Jupyter Hub

JupyterHub starts with HTTPS by default, but this time I haven't set up a TLS certificate. A self-signed certificate (Oreore certificate) is fine, but it is troublesome, so start it with HTTP with the --no-ssl option.

jupyterhub --no-ssl

2017-02-05_3.png

This will start it. JupyterHub is published on port number 8000, HTTP.

As an aside, it is recommended to put this command between nohup and & to boot the OS in the background.


nohup jupyterhub --no-ssl &

Visit Jupyter Hub

Access Jupyter Hub from a web browser on your PC. The URL is http: // : 8000 /.

2017-02-05_4.png

There is a message saying "Yogora (# ゚ Д ゚)" in HTTPS. Let's make a certificate later (^ _ ^;).

(Added on 2018/04/27: It seems that the certificate can be letsencrypt. https://jupyterhub.readthedocs.io/en/0.7.2/getting-started.html#ssl-encryption)

Enter your username and password to log in. After that, it can be used in the same way as Jupyter Notebook, so I will omit it.

Reference URL: http://jupyterhub.readthedocs.io/en/latest/index.html https://www.continuum.io/downloads

Recommended Posts

Build Jupyter Hub
Build Jupyter Lab (Python) environment with Docker
Jupyter begins
Jupyter Tips 4
Jupyter nbextensions
Jupyter Tips 5
Jupyter Tips 3
Jupyter Tips 2
Build the execution environment of Jupyter Lab
Build jupyter notebook on remote server (CentOS)
Jupyter installation
Jupyter tricks
Build python 1.0