Free Tier: Install Spring Boot on an Oracle Linux Instance
In this tutorial, use an Oracle Cloud Infrastructure Free Tier account to set up an Oracle Linux compute instance. Then, install a Spring Boot application and access your new app from the internet. Finally, this tutorial covers all the steps necessary to set up a virtual network for your host and connect the host to the internet.
Key tasks include how to:
- Set up a compartment for your development work.
- Install your Oracle Linux instance and connect it to your Virtual Cloud Network
(VCN).
- Set up an Oracle Cloud Infrastructure virtual cloud network and related network services required for your host to connect to the internet.
- Set up
ssh
encryption keys to access your Oracle Linux Server.
- Configure ingress rules for your VCN.
- Configure Spring Boot on your instance.
- Connect to your instance from the internet.
Here is a simplified diagram of the setup for your Linux instance.
For additional information, see:
Before You Begin
To successfully complete this tutorial, you must have the following:
- An Oracle Cloud Infrastructure Free Tier account. Start for free.
- A MacOS, Linux, or Windows computer with
ssh
support installed.
1. Set up a Compartment for Development
Configure a compartment for your development.
Create a compartment for the resources that you create in this tutorial.
- Sign in to the Oracle Cloud Infrastructure Console.
- Open the navigation menu and click Identity & Security. Under Identity, click Compartments.
- Click Create Compartment.
- Fill in the following information:
- Name:
<your-compartment-name>
- Description:
Compartment for <your-description>.
- Parent Compartment:
<your-tenancy>(root)
- Name:
- Click Create Compartment.
Reference: Create a compartment
2. Install an Oracle Linux Instance
Use the Create a VM Instance workflow to create a new compute instance.
The workflow does several things when installing the instance:
- Creates and installs a compute instance running Oracle Linux.
- Creates a VCN with the required subnet and components needed to connect the Oracle Linux instance to the internet.
- Creates an
ssh
key pair you use to connect to the instance.
To get started installing an instance with the Create a VM instance workflow, follow these steps:
The steps provided are for a Free Tier account. If you are using a paid account, the steps might differ from those shown here.
3. Enable Internet Access
The Create a VM Instance wizard automatically creates a VCN for your instance. You add an ingress rule to your subnet to allow internet connections on port 8080.
Follow these steps to select your VCN's public subnet and add the ingress rule.
4. Install and Configure Spring Boot
Next, install all the software needed for your Spring Boot application.
- Open the navigation menu and click Compute. Under Compute, click Instances.
- Click the link to the instance you created in the previous step.
From the Instance Details page look under the Instance Access section. Write down the public IP address the system created for you. You use this IP address to connect to your instance.
- Open a Terminal or Command Prompt window.
- Change into the directory where you stored the
ssh
encryption keys you created. - Connect to your instance with this SSH command
ssh -i <your-private-key-file> opc@<x.x.x.x>
Since you identified your public key when you created the instance, this command logs you into your instance. You can now issue
sudo
commands to install and start your server. - Enable an HTTP connection on port 8080.
sudo firewall-cmd --permanent --add-port=8080/tcp
sudo firewall-cmd --reload
The firewall is configured for Spring Boot.
Install Git v2 using the IUS Community Project (https://ius.io/). Navigate to the current
version of Git core package and download to a ~/temp
directory.
- For example, downloading the Git RPM looks similar to the following.
cd mkdir temp cd ~/temp wget https://repo.ius.io/7/x86_64/packages/g/git224-core-2.24.2-1.el7.ius.x86_64.rpm
- Install the RPM with
yum
.sudo yum install git224-core-2.24.2-1.el7.ius.x86_64.rpm
- Test result.
git --version git version 2.24.2
Git is installed.
- Install OpenJDK 8 using
yum
.sudo yum install java-1.8.0-openjdk-devel java -version
- Set
JAVA_HOME
in.bashrc
.Update the file:
vi ~/.bashrc
In the file, append the following text and save the file:
# set JAVA_HOME export JAVA_HOME=/etc/alternatives/java_sdk
Activate the preceding command in the current window.
source ~/.bashrc
Java is installed.
Install Maven from an Apache mirror. Go to the main Maven site's (https://maven.apache.org/) download page. Get the URL for the latest version and download with wget.
- Download the Maven zip file, for example:
wget http://apache.mirrors.pair.com/maven/maven-3/3.6.3/binaries/apache-maven-3.6.3-bin.tar.gz
- Extract the program files.
sudo tar xvfz apache-maven-3.6.3-bin.tar.gz
- Install the program files by moving the files to the
/opt
directory.sudo mv apache-maven-3.6.3 /opt/
- Add the Maven path
/opt/apache-maven-3.6.3/bin
to yourPATH
environment variable and source your.bashrc
.vi ~/.bashrc export PATH=$PATH:/opt/apache-maven-3.6.3/bin source ~/.bashrc
Maven is ready to use.
Follow these steps to set up your Spring Boot application:
What's Next
You have successfully installed and deployed a Spring Boot app on Oracle Cloud Infrastructure using a Linux instance.
To explore more information about development with Oracle products: