The Nautilus application development team recently finished the beta version of one of their Java-based applications, which they are planning to deploy on one of the app servers in Stratos DC. After an internal team meeting, they have decided to use the tomcat application server. Based on the requirements mentioned below complete the task:
App Server 1.8086.ROOT.war file on Jump host at location /tmp.Deploy it on this tomcat server and make sure the webpage works directly on base URL i.e curl http://stapp01:8086
Install JVM
sudo yum install java-1.8.0-openjdk-devel -y
Create tomcat user
sudo groupadd tomcat
sudo useradd -M -U -d /opt/tomcat -s /bin/nologin -g tomcat tomcat
Create /opt/tomcat directory
sudo mkdir /opt/tomcat
Download tomcat and Extract
wget https://archive.apache.org/dist/tomcat/tomcat-9/v9.0.80/bin/apache-tomcat-9.0.80.tar.gz
sudo tar -xf apache-tomcat-9.0.80.tar.gz -C /opt/tomcat --strip-components=1
Set Permissions
sudo chown -R tomcat:tomcat /opt/tomcat
Create a systemd service
sudo vi /etc/systemd/system/tomcat.service
Copy and paste the following lines:
[Unit]
Description=Apache Tomcat Web Application Container
After=network.target
[Service]
Type=forking
User=tomcat
Group=tomcat
Environment="JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.362.b09-4.el9.x86_64"
Environment="CATALINA_PID=/opt/tomcat/temp/tomcat.pid"
Environment="CATALINA_HOME=/opt/tomcat"
Environment="CATALINA_BASE=/opt/tomcat"
ExecStart=/opt/tomcat/bin/startup.sh
ExecStop=/opt/tomcat/bin/shutdown.sh
RestartSec=10
Restart=always
[Install]
WantedBy=multi-user.target
Start daemon service
sudo systemctl daemon-reload
sudo systemctl enable tomcat
sudo systemctl start tomcat
Setup firewall, you can skip this step
sudo firewall-cmd --permanent --zone=public --add-port=8080/tcp
sudo firewall-cmd --reload
Test you can access using curl http://stapp01:8080. Now lets modify the port and deploy ROOT.war
To modify the port edit the /opt/tomcat/conf/server.xml and change port 8080 to 8086
vi /opt/tomcat/conf/server.xml
<Connector port="8086" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443"
maxParameterCount="1000"
/>
Take backup of /opt/tomcat/webapps/ROOT
cd /opt/tomcat/webapps
mv ROOT ROOT.bak
Copy /tmp/ROOT.war from jump host server to app server.
scp /tmp/ROOT.war tony@stapp01:/home/tony/
Unzip the ROOT.war
unzip /home/tony/ROOT.war -d /opt/tomcat/webapps/ROOT
Restart tomcat service
systemctl restart tomcat
Test
curl http://stapp01:8086
<!DOCTYPE html>
<!--
To change this license header, choose License Headers in Project Properties.
To change this template file, choose Tools | Templates
and open the template in the editor.
-->
<html>
<head>
<title>SampleWebApp</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<h2>Welcome to xFusionCorp Industries!</h2>
<br>
</body>
</html>
/bin (scripts), /conf (config), /webapps (applications)/