Jupyter Notebook, derived from IPython, is a widely used, interactive data science web application which can be used to create and share scientific computing-related documents.
This article will show you how to install Jupyter Notebook on a PlegmaHost CentOS 7 server instance for remote access.
Before getting started, you need to:
- Deploy a fresh PlegmaHost CentOS 7 server instance;
- Log in from an SSH terminal as a non-root sudo user, and let’s say the username is “juser”.
Step 1: Update the system and install dependencies
Use the following commands to update the system and install necessary packages for Jupyter Notebook.
sudo yum update -y sudo yum install bzip2 -y sudo shutdown -r now
After the reboot, use the same username and password to log into the system.
Step 2: Install Jupyter Notebook using Anaconda
Anaconda is an open data science platform consisting of many analytics applications, including Jupyter Notebook. By installing Anaconda, you will have installed Jupyter Notebook and many similar applications onto your system.
Download the appropriate version of Anaconda from the official Anaconda website to install it:
cd ~ wget http://repo.continuum.io/archive/Anaconda3-4.1.1-Linux-x86_64.sh sudo bash Anaconda3-4.1.1-Linux-x86_64.sh
At the beginning the installation, continuously press ENTER until you are presented with question below:
Do you approve the license terms? [yes|no]
yes, and then press ENTER:
Then you will be asked to confirm the installing location:
Anaconda3 will now be installed into this location: /root/anaconda3 - Press ENTER to confirm the location - Press CTRL-C to abort the installation - Or specify a different location below
You can specify the installing location
[/root/anaconda3] >>> /opt/anaconda3
When presented with the following question, press ENTER to finish the installation:
Do you wish the installer to prepend the Anaconda3 install location to PATH in your /root/.bashrc ? [yes|no] [no] >>> ENTER
Instead of modifying the per-user configuration file “/root/.bashrc”, you can perform a system-wide setup modification for all users:
sudo cp /etc/profile /etc/profile_backup echo 'export PATH=/opt/anaconda3/bin:$PATH' | sudo tee -a /etc/profile source /etc/profile echo $PATH
Step 3: Configure Jupyter Notebook
Now that Jupyter Notebook has been installed onto your system, you will need to configure it before you can access it remotely.
Generate a configuration file:
cd ~ jupyter notebook --generate-config
This command will create a default Jupyter Notebook configuration file:
For security purposes, use the following commands to setup a password for your Jupyter Notebook server:
python >>> from notebook.auth import passwd >>> passwd() Enter password:<your-password> Verify password:<your-password> 'sha1:<your-sha1-hash-value>' >>> Ctrl+Z
Save the SHA1 hash value for later use, which will look like:
Create a self-signed certificate and the matched key:
cd ~ openssl req -x509 -nodes -days 365 -newkey rsa:4096 -keyout jkey.key -out jcert.pem
The above command will generate a certificate file
/home/juser/jcert.pem and the matched key file
Open the default configuration file using the vi editor:
Find each line below respectively:
# c.NotebookApp.password = '' # c.NotebookApp.port = 8888 # c.NotebookApp.ip = 'localhost' # c.NotebookApp.open_browser = True # c.NotebookApp.certfile = '' # c.NotebookApp.keyfile = ''
Modify each of them as below:
c.NotebookApp.password = 'sha1:<your-sha1-hash-value>' c.NotebookApp.port = 8888 c.NotebookApp.ip = '*' c.NotebookApp.open_browser = False c.NotebookApp.certfile = '/home/juser/jcert.pem' c.NotebookApp.keyfile = '/home/juser/jkey.key'
Save and quit:
Modify firewall rules in order to allow inbound traffic on port 8888:
sudo firewall-cmd --zone=public --add-port=8888/tcp --permanent sudo systemctl restart firewalld.service
Start the Jupyter Notebook server:
Finally, visit “https://<your-server-IP>:8888” from your browser, ignore the security warning, and use the password you set earlier to log in.