Jupyter Notebook Server untuk Single-User


Tulisan sebelumnya telah membahas bagaimana cara menginstall Jupyter Notebook Server untuk multi-user menggunakan JupyterHub. Sedangkan untuk single-user, ini akan sedikit lebih mudah tanpa harus menginstall Jupyterub. Dalam contoh ini, saya menginstall Jupyter pada Raspberry Pi 3.

Pastikan Jupyter Notebook anda sudah terinstall.

pi@raspberry:~ $ sudo apt-get install python3-pip
pi@raspberry:~ $ sudo pip3 install jupyter


Kemudian buat file konfigurasi untuk Jupyter Notebook pada Jupyter folder, "~/.jupyter", menggunakan perintah berikut:

pi@raspberry:~ $ jupyter notebook --generate-config

File konfigurasi dapat dilihat di Jupyter folder

pi@raspberry:~ $ cd .jupyter
pi@raspberry:~/.jupyter $ ls
jupyter_notebook_config.py


Seperti yang terlihat di atas, "jupyter_notebook_config.py" terdapat di folder ~/.jupyter

Ada beberapa langkah lagi yang harus dilakukan:
1. Menggunakan SSL encryption untuk mengaktifkan https dengan membuat SSL certificate yaitu

pi@raspberry:~/.jupyter $ openssl req -x509 -nodes -newkey rsa:1024 -keyout my.key -out my.cert

2. Menambahkan informasi SSL certificate pada file konfigurasi jupyter untuk mengaktifkan https.
3. Pastikan Jupyter Notebook dapat menerima akses dari luar dengan menambahkan c.NotebookApp.ip = '*' pada file konfigurasi.
3. Membuat hashed password yang akan digunakan saat kita login.
4. Menentukan port saat mengakses ip address dari Jupyter Notebook, misal 9999.
5. Menonaktifkan "open_browser" saat Jupyter Notebook Server dijalankan pada Raspberry Pi 3.

Tahap 2-6 dapat diringkas ke dalam satu script python seperti contoh di bawah.

pi@raspberry:~/.jupyter $ sudo nano main.py
kemudian ketik kode berikut pada main.py

from notebook.auth import passwd

print("Masukan Password Anda \n")
my_passwd = passwd()

File_konfig = open("./jupyter_notebook_config.py","a")
File_konfig.write("c.NotebookApp.certfile = u'/home/pi/.jupyter/my.cert'\n")
File_konfig.write("c.NotebookApp.keyfile = u'/home/pi/.jupyter/my.key'\n")
File_konfig.write("c.NotebookApp.ip = '*'\n")
File_konfig.write("c.NotebookApp.password = u'" + my_passwd + "'\n")
File_konfig.write("c.NotebookApp.open_browser = False\n")
File_konfig.write("c.NotebookApp.port = 9999\n")

File_konfig.close()

Jangan lupa "Ctrl-X" dan ketik "y" untuk menyimpan file. Setelah itu jalan "main.py" dengan mengetik

pi@raspberry:~/.jupyter $ python3 main.py

Langkah terakhir adalah menjalankan jupyter notebook

pi@raspberry:~ $ jupyter notebook
[I 02:58:33.101 NotebookApp] Serving notebooks from local directory: /home/pi/.jupyter
[I 02:58:33.102 NotebookApp] 0 active kernels
[I 02:58:33.102 NotebookApp] The Jupyter Notebook is running at: https://localhost:9999/
[I 02:58:33.102 NotebookApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).
^C[I 02:58:43.344 NotebookApp] interrupted
Serving notebooks from local directory: /home/pi/.jupyter
0 active kernels
The Jupyter Notebook is running at: https://localhost:9999/
Shutdown this notebook server (y/[n])? y
[C 02:58:44.647 NotebookApp] Shutdown confirmed
[I 02:58:44.649 NotebookApp] Shutting down kernels


Gunakan Ctrl-C untuk menstop server.

Akses Jupyter Notebook dengan mengetik misal https://192.168.10.101:9999 Tampilan login Jupyter Notebook Server untuk Single-User adalah seperti di bawah ini