About Configuring Your System

Before installing software on your instance, you must configure it to accept traffic over the Internet from your local computer.

After you set up access, install Anaconda and then create the machine learning environments that you'll use.

Set up your Oracle Cloud Infrastructure Compute Instance

Edit the security list for the virtual cloud network that your instance uses, then update the firewall rules for your instance.

You use the security list to specify the traffic that's allowed to flow over the virtual cloud network that your instance uses. After the security list for the network is set up, you must update the firewall rules on your instance to allow access to that traffic. In this case open port 8888, which is the default port for Jupyter Notebook.

It's easiest to use stateful rules. In essence, a stateful rule allows both ingress and egress on the selected port. If you set up a stateless ingress rule, then you must also set up a corresponding egress rule.

  1. Add ingress rules for Jupyter Notebook, which uses port 8888 by default.
    1. Log into Oracle Cloud console and open the navigation menu.
    2. Go to Networking and click Virtual Cloud Networks.
    3. Click the cloud network that you're interested in.
    4. Under Resources click Security Lists then click the security list that you're interested in.
    5. Under Resources, click Ingress Rules then click Add Ingress Rules.
    6. Enter 0.0.0.0/0 for the Source CIDR, TCP for the IP Protocol, and 8888 for the destination port range.
    7. Click Add Ingress Rules.
  2. Update firewall rules.

    The command that's shown here opens port 8888, which is the default port for Jupyter Notebook.

    On Oracle Linux:

    sudo firewall-cmd --zone=public --add-port=8888/tcp --permanent
    sudo firewall-cmd --reload

    On Ubuntu:

    sudo iptables -I INPUT -p tcp -s 0.0.0.0/0 --dport 8888 -j ACCEPT
    sudo service netfilter-persistent save

    Note:

    On an Ubuntu instance in Oracle Cloud Infrastructure Compute, do not use Uncomplicated Firewall (UFW) to manage the firewall.

Install Anaconda Distribution

Use Anaconda and its package manager to set up and maintain individual machine learning environments on your compute instance.

You can get the latest installer from https://repo.continuum.io/archive/. These instructions assume that the operating system is either Oracle Linux 7.7 or Ubuntu 18.04, and that the version of Anaconda Distribution is 2019.10 with Python 3.7.

  1. Connect to your compute instance with SSH or PuTTY.
  2. Download Anaconda3 and make sure that the checksum matches the checksum that's published on the Anaconda installer archive page at https://repo.continuum.io/archive/.
    wget https://repo.continuum.io/archive/Anaconda3-2019.10-Linux-x86_64.sh
    md5sum Anaconda3-2019.10-Linux-x86_64.sh
  3. Run the install script then add Anaconda to your path.
    bash Anaconda3-2019.10-Linux-x86_64.sh -b
    echo -e 'export PATH="$HOME/anaconda3/bin:$PATH"' >> $HOME/.bashrc
    source ~/.bashrc
  4. Make sure you have the latest conda.
    conda update -n base -c defaults conda
  5. Configure your shell to use the conda activate command.
    conda init bash
    source ~/.bashrc

    After your shell is configured, the current Anaconda environment is added to your command line prompt. When the base environment is activated, your command line should be similar to one the following examples, depending on your operating system:

    (base) [opc@instancename ~]$
    (base) [ubuntu@instancename ~]$

Set Up a Machine Learning Sandbox Environment on Oracle Linux

Create a separate sandbox environment and install TensorFlow and Jupyter Notebook.

Create an environment and give it the name sandbox. An environment is isolated from rest of the compute instance so that tools and software that you install into the sandbox environment are specific to the sandbox environment. You can have several environments on one compute instance, each with its own individual configuration.

In the following procedure, you install TensorFlow 2 and Jupyter Notebook, but they are not the only tools available. Anaconda Distribution has over 1,500 machine learning packages that you can install, including scikit-learn, pandas, and RStudio.

Note:

Because the default Python on Oracle Linux is Python 2, you need to make sure that the sandbox environment is created with Python 3 in Step 2. Specify Python 3.7 because at the time of this writing, the latest Tensorflow (2.0.0) does not work with Python 3.8.

Before you begin, make sure you have the latest Anaconda Distribution installed. In these instructions, it's assumed that you have downloaded and installed Anaconda3-2019.10-Linux-x86_64.
  1. Connect to your compute instance with SSH or PuTTY.
  2. Create a new environment called sandbox.
    conda create --name sandbox pip python=3.7
  3. Activate the environment that you just created.
    conda activate sandbox
  4. Install Jupyter Notebook.
    conda install notebook
  5. Install Tensorflow.
    python -m pip install tensorflow-gpu
    If your instance doesn't have a GPU, use the following command instead:
    python -m pip install tensorflow
  6. Generate a Jupyter Notebook configuration file.
    jupyter notebook --generate-config

    The configuration file is created in /home/opc/.jupyter/jupyter_notebook_config.py, which is outside the environment. As a result, the configuration applies to every Jupyter Notebook instance, no matter which environment it is in.

  7. Open the configuration file in a text editor such as nano or vi, and add the following lines to the beginning:
    c = get_config()
    c.NotebookApp.ip = '0.0.0.0'
    c.NotebookApp.open_browser = False
    c.NotebookApp.port = 8888
  8. Add a password to Jupyter Notebook. When prompted, enter a suitably strong password. You can run this command any time that you want to change the password.
    jupyter notebook password
  9. Install a certificate for encrypted communications over HTTPS. To install a self-signed certificate:
    openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout jupyter-key.key -out jupyter-cert.pem
  10. Start Jupyter Notebook.
    jupyter notebook --certfile=jupyter-cert.pem --keyfile=jupyter-key.key

If the ingress rules and firewall settings of your instance are correct, you should be able to open Jupyter Notebook in a web browser by navigating to https://<instance-ip-address>:8888.

Set Up a Machine Learning Sandbox Environment on Ubuntu

Create a separate sandbox environment and install TensorFlow and Jupyter Notebook.

Create an environment and give it the name sandbox. An environment is isolated from rest of the instance so that tools and software that you install into the sandbox environment are specific to the sandbox environment. You can have several environments on one compute instance, each with its own individual configuration.

In the following procedure, you install TensorFlow 2 and Jupyter Notebook, but they are not the only tools available. Anaconda Distribution has over 1,500 machine learning packages that you can install, including scikit-learn, pandas, and RStudio.

Before you begin, make sure you have the latest Anaconda Distribution installed. In these instructions, it's assumed that you have downloaded and installed Anaconda3-2019.10-Linux-x86_64.
  1. Connect to your compute instance with SSH or PuTTY.
  2. Create a new environment called sandbox.
    conda create --name sandbox
  3. Activate the environment that you just created.
    conda activate sandbox
  4. Install Tensorflow into the sandbox environment. The latest Tensorflow now includes Keras.
    python -m pip install tensorflow-gpu
    If your instance doesn't have a GPU, use the following command instead:
    python -m pip install tensorflow
  5. Generate a Jupyter Notebook configuration file.
    jupyter notebook --generate-config

    The configuration file is created in /home/ubuntu/.jupyter/jupyter_notebook_config.py, which is outside the environment. As a result, the configuration applies to every Jupyter Notebook instance, no matter which environment it is in.

  6. Open the configuration file in a text editor such as nano or vi, and add the following lines to the beginning:
    c = get_config()
    c.NotebookApp.ip = '0.0.0.0'
    c.NotebookApp.open_browser = False
    c.NotebookApp.port = 8888
  7. Add a password to Jupyter Notebook. When prompted, enter a suitably strong password. You can run this command any time that you want to change the password.
    jupyter notebook password
  8. Install a certificate for encrypted communications over HTTPS. To install a self-signed certificate:
    openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout jupyter-key.key -out jupyter-cert.pem
  9. Start Jupyter Notebook.
    jupyter notebook --certfile=jupyter-cert.pem --keyfile=jupyter-key.key

If the ingress rules and firewall settings of your instance are correct, you should be able to open Jupyter Notebook in a web browser by navigating to https://<instance-ip-address>:8888.