In the article https://blogs.oracle.com/pshuff/installing-tomcat-on-oracle we saw how to install tomcat in the Oracle Cloud Gen 1, we will now look at the same process but in Oracle Cloud Gen 2.
We will talk you through the manual steps to installing Tomcat on Oracle Linux 7 compute instance in the Oracle Cloud.
*This example below uses only the compute instance to store all the data. For back up and recovery purpose it is recommended to use Oracle’s Block storage to contain your tomcat installation. This allows easy back up and the ability to attach/detach the block storage to a new compute instance. This will be covered in this accompanying article here.
Versions - Tomcat 9, Java 8 and Oracle Linux 7(OL7)
We will step through:
Creating an Oracle Enterprise Linux instance on the Oracle Cloud Compute Service
Install Java 8 and Tomcat 9
Update iptables to open port 80 and 443
First we need to create our Oracle Linux compute instance. Navigate to the Oracle Cloud Compute instances page with in the Oracle Cloud Infrastructure console.
Click the create instance button.
Enter a name for your instance. Oracle Linux 7.7 Image Build:2020.01.28-0 has been pre-selected. Select your Availability Domain, Instance Type, networking options.
If you wish your tomcat/system to be accessible from the internet make sure “Assign a public IP address” is checked.
Before hitting make sure you add you public ssh key. Choose SSH key file (.pub) from your computer or paste into the textarea.
Wait for your new system to be provisioned.
One it is ready you will see it appear in the compute instances page. By clicking on the instance name you will be directed to the Instance Details page. Here you will see your Public IP address under the section “Primary VNIC Information”. Take note of your new IP address.
Take not of the IP address of your system. This can be found. You will need this for later steps.
First I locally downloaded the software:
Java (I used jdk-8u241-linux-x64.rpm) click to “Accept the Licence Agreement” to download.
Apache Tomcat (I used apache-tomcat-9.0.30.tar.gz) You can use curl directly in the box if you prefer.
To install Java you need download the rpm file and in this case we take the version jdk-8u241-linux-x64.rpm.
You will need to use scp to copy the file over to the new box
$ scp version jdk-8u241-linux-x64.rpm opc@yourIPhere:/tmp
You can also use a gui tool like WINSCP to copy this file over. Also copy the tomcat apache-tomcat-9.0.30.tar.gz to this directory.
Access the box with ssh. We need to login as opc so that we can execute sudo and install packages. You can use a gui tool like Putty. Making sure to add your authentication key to the Connection/SSH/Auth settings page.
$ sudo rpm -ivh jdk-8uversion-linux-x64.rpm
RPM installs the JDK into the /usr/java/ directory. Next set your system to use the Oracle JDK.
$ sudo alternatives --install /usr/bin/java java /usr/java/jdk1.8.0_version/bin/java 200000
Use the alternatives command to switch to the Oracle JDK.
$ sudo alternatives --config java
Verify it is now installed ok:
$ java -version
java version "1.8.0_241"
Java HotSpot(TM) 64-Bit Server VM (build 25.241-b07, mixed mode)
First create a user tomcat:
$ sudo useradd tomcat
$ sudo mkdir -p /u01
$ sudo chown tomcat:tomcat /u01
$ sudo su - tomcat
$ mkdir -p /u01/tomcat
$ cd /u01/tomcat
$ tar xzf /tmp/apache-tomcat-9.0.30.tar.gz
$ ln -s apache-tomcat-9.0.30 latest$ cd /u01/tomcat/apache-tomcat-9.0.30/bin
Using CATALINA_BASE: /u01/tomcat/apache-tomcat-9.0.30
Using CATALINA_HOME: /u01/tomcat/apache-tomcat-9.0.30
Using CATALINA_TMPDIR: /u01/tomcat/apache-tomcat-9.0.30/temp
Using JRE_HOME: /
Using CLASSPATH: /u01/tomcat/apache-tomcat-9.0.30/bin/bootstrap.jar:/u01/tomcat/apache-tomcat-9.0.30/bin/tomcat-juli.jar
To verify things are ok run:
$ wget http://localhost:8080
--2020-02-06 11:10:58-- http://localhost:8080/
Resolving localhost (localhost)... 127.0.0.1, ::1
Connecting to localhost (localhost)|127.0.0.1|:8080... connected.
HTTP request sent, awaiting response... 200
Length: unspecified [text/html]
Saving to: ‘index.html’
[ <=> ] 11,196 --.-K/s in 0s
2020-02-06 11:10:59 (27.4 MB/s) - ‘index.html’ saved 
First lets check where the java refers to:
$ sudo update-alternatives --config java
There are 2 programs which provide 'java'.
*+ 2 /usr/java/jdk1.8.0_241-amd64/bin/java
Enter to keep the current selection[+], or type selection number: 1
This command updates the links in to point to the program for this purpose. The links in are just symbolic links.
Confirm you are happy with this selection.
Using vim edit the . file. Here set the JAVA_HOME and CATALINA_HOME variables
$ sudo su – tomcat
Insert the following:
Your file should look like this:
$ more /home/tomcat/.bash_profile
# Get the aliases and functions
if [ -f ~/.bashrc ]; then
# User specific environment and startup programs
You should log out and in to verify this is applied.
When using tomcat user run the following and you see:
-bash: /bin/startup.sh: No such file or directory
If you see this verify that the link to the “latest” tomcat is correct. In my case it was pointing one directory up so I navigated to the correct directory and reset the link using:
[tomcat@instance-xxxxxxx-xxxx apache-tomcat-9.0.30]$ ln -s apache-tomcat-9.0.30 latest
[tomcat@instance-xxxxxxx-xxxx apache-tomcat-9.0.30]$ $CATALINA_HOME/bin/startup.sh
-bash: /bin/startup.sh: No such file or directory
[tomcat@instance-xxxxxxx-xxxx apache-tomcat-9.0.30]$ exit
[opc@instance-xxxxxxx-xxxx etc]$ sudo su - tomcat
Last login: Thu Feb 6 11:43:58 GMT 2020 on pts/2
[tomcat@instance-xxxxxxx-xxxx ~]$ $CATALINA_HOME/bin/startup.sh
Using CATALINA_BASE: /u01/tomcat/latest
Using CATALINA_HOME: /u01/tomcat/latest
Using CATALINA_TMPDIR: /u01/tomcat/latest/temp
Using JRE_HOME: /u01/java/latest
Using CLASSPATH: /u01/tomcat/latest/bin/bootstrap.jar:/u01/tomcat/latest/bin/tomcat-juli.jar
Again, run wget to if you want to verify this returns your index.html:
Once Tomcat is running we need to update the iptables to add ports 80, 8080, and 443 as pass through ports. Perform the following.
# add ssh port as permanent opened port
sudo firewall-cmd --zone=public --add-port=80/tcp --permanent
sudo firewall-cmd --zone=public --add-port=443/tcp --permanent
sudo firewall-cmd --zone=public --add-port=8080/tcp --permanent
sudo firewall-cmd –reload
From within the compute instance details page you should be able to see the “Subnet: Public Subnet” Click the public subnet hyperlink. This will take you to the Virtual Cloud Network settings used by your compute instance.
Select the Security List option from the Resources menu listed on the left.
Click “Default Security List for VirtualCloudNetwork-XXX-XXX” from the table of security lists.
Here we will add the ports 80, 443, and 8080:
Wait a couple of seconds and navigate to your ip followed by port 8080. You should see this: