DigitalOcean is well known for low rates for smaller cloud instances which costs only 5 USD per month or 0.007 USD per hour, so I’m going to use it for about 2 hours, destroy it, and get charged just 0.014 USD.
The goal of this post is to set up a Droplet on DigitralOcean that has a Python 3.8 installation plus packages (NumPy and pandas) in combination with a secure password and SSL encrypted Jupyter Lab server installtion.
RSA Public and Private Keys
SSL certificate consisting of RSA public and private keys is needed. I’m going to use OpenSSL to generate RSA which is a self generated certificate.
openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout mykey.key -out mycert.pem
Create a new Droplet with options to thiese:
Operating System | Ubuntu 20.04 LTS x64 |
Size | Two core, 2GB, 60GB SSD (standard Droplet) |
Data center region | nearest to your location |
SSH key | Add a (new) SSH key for password-less login |
Droplet name | Prespecified name or something like pyalgo |
Create a SSH Key
ssh-keygen
# test
ssh -i ~/.ssh/id_rsa root@147.182.138.31
Create a file and save it in same directory
install.sh
#!/bin/bash
#
# Script to Install
# Linux System Tools and Basic Python Components
# as well as to
# Start Jupyter Lab Server
#
# Python for Algorithmic Trading
# (c) Dr. Yves J. Hilpisch
# The Python Quants GmbH
#
# GENERAL LINUX
apt-get update # updates the package index cache
apt-get upgrade -y # updates packages
# install system tools
apt-get install -y build-essential git # system tools
apt-get install -y screen htop vim wget # system tools
apt-get upgrade -y bash # upgrades bash if necessary
apt-get clean # cleans up the package index cache
# INSTALLING MINICONDA
wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh \
-O Miniconda.sh
bash Miniconda.sh -b # installs Miniconda
rm -rf Miniconda.sh # removes the installer
# prepends the new path for current session
export PATH="/root/miniconda3/bin:$PATH"
# prepends the new path in the shell configuration
cat >> ~/.profile <<EOF
export PATH="/root/miniconda3/bin:$PATH"
EOF
# INSTALLING PYTHON LIBRARIES
conda install -y jupyter # interactive data analytics in the browser
conda install -y jupyterlab # Jupyter Lab environment
conda install -y numpy # numerical computing package
conda install -y pytables # wrapper for HDF5 binary storage
conda install -y pandas # data analysis package
conda install -y scipy # scientific computations package
conda install -y matplotlib # standard plotting library
conda install -y seaborn # statistical plotting library
conda install -y quandl # wrapper for Quandl data API
conda install -y scikit-learn # machine learning library
conda install -y openpyxl # package for Excel interaction
conda install -y xlrd xlwt # packages for Excel interaction
conda install -y pyyaml # package to manage yaml files
pip install --upgrade pip # upgrading the package manager
pip install q # logging and debugging
pip install plotly # interactive D3.js plots
pip install cufflinks # combining plotly with pandas
pip install tensorflow # deep learning library
pip install keras # deep learning library
pip install eikon # Python wrapper for the Refinitiv Eikon Data API
# Python wrapper for Oanda API
pip install git+git://github.com/yhilpisch/tpqoa
# COPYING FILES AND CREATING DIRECTORIES
mkdir -p /root/.jupyter/custom
wget http://hilpisch.com/custom.css
mv custom.css /root/.jupyter/custom
mv /root/jupyter_notebook_config.py /root/.jupyter/
mv /root/mycert.pem /root/.jupyter
mv /root/mykey.key /root/.jupyter
mkdir /root/notebook
cd /root/notebook
# STARTING JUPYTER LAB
jupyter lab &
jupyter_notebook_config.py
#
# Jupyter Notebook Configuration File
#
# Python for Algorithmic Trading
# (c) Dr. Yves J. Hilpisch
# The Python Quants GmbH
#
# SSL ENCRYPTION
# replace the following file names (and files used) by your choice/files
c.NotebookApp.certfile = u'/root/.jupyter/mycert.pem'
c.NotebookApp.keyfile = u'/root/.jupyter/mykey.key'
# IP ADDRESS AND PORT
# set ip to '*' to bind on all IP addresses of the cloud instance
c.NotebookApp.ip = '0.0.0.0'
# it is a good idea to set a known, fixed default port for server access
c.NotebookApp.port = 8888
# PASSWORD PROTECTION
# here: 'jupyter' as password
# replace the hash code with the one for your password
c.NotebookApp.password = \
'sha1:da3a3dfc0445:052235bb76e56450b38d27e41a85a136c3bf9cd7'
# NO BROWSER OPTION
# prevent Jupyter from trying to open a browser
c.NotebookApp.open_browser = False
# ROOT ACCESS
# allow Jupyter to run from root user
c.NotebookApp.allow_root = True
setup.sh
#!/bin/bash
#
# Setting up a DigitalOcean Droplet
# with Basic Python Stack
# and Jupyter Notebook
#
# Python for Algorithmic Trading
# (c) Dr Yves J Hilpisch
# The Python Quants GmbH
#
# IP ADDRESS FROM PARAMETER
MASTER_IP=$1
# COPYING THE FILES
scp install.sh root@${MASTER_IP}:
scp mycert.pem mykey.key jupyter_notebook_config.py root@${MASTER_IP}:
# EXECUTING THE INSTALLATION SCRIPT
ssh root@${MASTER_IP} bash /root/install.sh
bash setup.sh $IP_address
locate to your IP address with port number 8888 for example:
147.182.138.31:8888
You should see this message
The password is “jupyter”