Jupyter Hub on Ubuntu server 18.04

En este artículo explico como instalar y configurar Jupyter Hub sobre Ubuntu server 18.04 con el kernel para Python3 y Java.

Instalación

1. Cambiar a usuario root

administrador@jupyter:~$ sudo -i

2. Instalar nodejs

root@jupyter:~# curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash -
root@jupyter:~# apt-get -y install nodejs

3. Instalar pip

root@jupyter:~# apt-get -y install python3-pip

4. Instalar npm

root@jupyter:~# npm install -g configurable-http-proxy

5. Instalar jupyterhub y notebook

root@jupyter:~# pip3 install jupyterhub
root@jupyter:~# pip3 install --upgrade notebook

6. Crear archivo de configuración de jupyter hub.

root@jupyter:~# mkdir /etc/jupyterhub
root@jupyter:~# jupyterhub --generate-config -f /etc/jupyterhub/jupyterhub_config.py

7. Modificar el archivo de configuración

root@jupyter:~# vi /etc/jupyterhub/jupyterhub_config.py
# Configuration file for jupyterhub.

# The public facing port of the proxy
c.JupyterHub.port = 80

# Create system users that don't exist yet
c.LocalAuthenticator.create_system_users = True
c.Authenticator.add_user_cmd = ['adduser', '--force-badname', '-q', '--gecos', '""', '--disabled-password']

# Set of users who can administer the Hub itself 
c.Authenticator.admin_users = {'UserAdmin'}

8. Agregar un usuario para probar.

  • usuario = test
  • contraseña = test
root@jupyter:~# adduser test
Adding user `test' ...
Adding new group `test' (1001) ...
Adding new user `test' (1001) with group `test' ...
Creating home directory `/home/test' ...
Copying files from `/etc/skel' ...
Enter new UNIX password: 
Retype new UNIX password: 
passwd: password updated successfully
Changing the user information for test
Enter the new value, or press ENTER for the default
Full Name []: 
Room Number []: 
Work Phone []: 
Home Phone []: 
Other []: 
Is the information correct? [Y/n] y

9. Ejecutar el servidor

root@jupyter:~# jupyterhub --config /etc/jupyterhub/jupyterhub_config.py

10. Probar. Abrir el navegador,colocar colocar la dirección del servidor y autenticarse con las credenciales del usuario test.

Ejecución de Jupyter Hub en un navegador

11. Crear el servicio

root@jupyter# vi /etc/systemd/system/jupyter.service
[Unit]
Description=Jupyterhub
After=syslog.target network.target

[Service]
User=root
Environment="PATH=/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin"
ExecStart= /usr/local/bin/jupyterhub --config /etc/jupyterhub/jupyterhub_config.py

[Install]
WantedBy=multi-user.target

12. Iniciar el servicio

root@jupyter:~# systemctl start jupyter.service

13. Habilitar el servicio cuando inicia la máquina

root@jupyter:~# systemctl enable jupyter.service

Paquetes adicionales

1. Paquetes para exportar a PDF

root@jupyter:~# apt-get install texlive texlive-xetex texlive-latex-extra pandoc

Java kernel

Referencia: https://github.com/SpencerPark/IJava

1. Instalar el jdk

administrador@jupyter:~$ sudo apt install default-jdk

2. Verificar la versión de java

administrador@jupyter:~$ java -version
openjdk version "10.0.2" 2018-07-17
OpenJDK Runtime Environment (build 10.0.2+13-Ubuntu-1ubuntu0.18.04.4)
OpenJDK 64-Bit Server VM (build 10.0.2+13-Ubuntu-1ubuntu0.18.04.4, mixed mode)

3. Verificar que se encuentra instalado jshell

administrador@jupyter:~$ java --list-modules | grep "jdk.jshell"
jdk.jshell@10.0.2

4. Descargar los binarios

administrador@jupyter:~$ sudo -i
root@jupyter:~# cd /tmp/
root@jupyter:/tmp# wget https://github.com/SpencerPark/IJava/releases/download/v1.2.0/ijava-1.2.0.zip
root@jupyter:/tmp# unzip ijava-1.2.0.zip

5. Instalar el kernel

root@jupyter:/tmp# python3 install.py --sys-prefix
Installed java kernel into "/usr/share/jupyter/kernels/java"

6. Verificar la instalación del kernel

root@jupyter:/tmp# jupyter kernelspec list
Available kernels:
python3 /usr/local/share/jupyter/kernels/python3
java /usr/share/jupyter/kernels/java

7. Modificar el timeout

administrador@jupyter:~$ sudo vi /usr/share/jupyter/kernels/java/kernel.json
{
"argv": [
"java",
"-jar",
"/usr/share/jupyter/kernels/java/ijava-1.2.0.jar",
"{connection_file}"
],
"display_name": "Java",
"env": {
"IJAVA_TIMEOUT":"3 SECONDS"
},
"interrupt_mode": "message",
"language": "java"
}

Deja un comentario

Tu dirección de correo electrónico no será publicada. Los campos obligatorios están marcados con *