In case I forgot this once I want to setup another tomcat, thus I write it down. Setting up tomcat requires java to be ready on the instance, I did the java setup in this post. We know that tomcat is running on port :8080 (default), in order to make it accessible publicly, new firewall rules setup in VPC Network is required.
Setup Firewall Rules
Following the guideline from gcp documentation in this post,
- Click on Go to the Firewall Page
- This page will be shown, then click +CREATE FIREWALL RULE
- Enter the following Fields:
- Name: name of the Firewall Rule. Name can be anything but it can have only lower case letters, hyphens and numbers
- Priority: Priority of Rule. Higher the number lower the priority. I keep the default value(1000)
- Direction of traffic: Ingress. Ingress applies to incoming traffic. Egress applies to outbound traffic.
- Action on match: allow.
- Targets: All instance in the network. Because if I plan to have more than one instance I want to make this available for all instance in the network.
- Source filter: IP Ranges
- Source IP Ranges: 0.0.0.0/0, means allow any IP, and anyone can send data
Once the firewall setup done, I continue to do the next one,
Installing Tomcat 8
After making sure firewall setup done, and having apache tomcat 8 package downloaded from its official download page, I copy the apache-tomcat-8.5.59.tar.gz to the home directory, then do these steps:
- Extracting tar.gz
- $ tar xvf apache-tomcat-8.5.59.tar.gz
- Copy apache-tomcat-8.5.59 into nginx html and rename it as tomcat8 (if you want to put it in another directory the location can differ.
- $ sudo mv apache-tomcat-8.5.59 /usr/share/nginx/html/tomcat8
- Change the owner of tomcat8 directory
- $ sudo chown -R myuser:myuser tomcat8
- Edit java security, because in the first try, I can’t get the normal tomcat, and it is because the java security (getting this info from stackoverflow, thanks Bij)
- go to java security directory, in my case, the directory is located here:
$ cd /usr/java/jdk1.8.0_271-amd64/jre/lib/security - using vi edit java.security file
$ sudo vi java.security - change securerandom.source=file:/dev/random to securerandom.source=file:/dev/./urandom
- go to java security directory, in my case, the directory is located here:
- Run tomcat
- $ cd /usr/share/nginx/html/tomcat8/bin
- ./startup.sh
- Check on the browser using PUBLIC_IP:8080
Reference:
1. google cloud computing official documentation
2. bytesofgigabytes web on setting up firewall in google cloud
3. bytesofgigabytes web on installing tomcat
4. stackoverflow answer posted by BiJ