Skip to main content

Command Palette

Search for a command to run...

Day 27: Tomcat Setup, Code Build & Deployment

Tomcat Setup, Code Build & Deployment using Vagrant VMs

Published
β€’2 min read
Day 27: Tomcat Setup, Code Build & Deployment

πŸ‘‹ Hey everyone! Welcome to Day 27 of my DevOps journey. This is the third article in my mini-series on setting up a complete Java stack manually using multi-stage Vagrant VMs.

πŸ› οΈ Recap So Far

In the past two days, we:

  • 🎯 Set up a multi-VM environment with Vagrant

  • 🧩 Explored plugins and provisioning options

  • πŸ—„οΈ Installed and configured services like MySQL, Memcached, and RabbitMQ

Now, it's time to set up the Tomcat application server and deploy the Java project.


β˜• Step 1: Login to Tomcat VM

vagrant ssh app01

Make sure the /etc/hosts file has valid hostname mappings for all services.


πŸ”§ Step 2: Install Prerequisites

sudo -i
yum update -y
yum install epel-release -y
dnf -y install java-11-openjdk java-11-openjdk-devel
dnf install git maven wget -y

πŸ“¦ Step 3: Install & Configure Tomcat

cd /tmp/
wget https://archive.apache.org/dist/tomcat/tomcat-9/v9.0.75/bin/apache-tomcat-9.0.75.tar.gz
tar xzvf apache-tomcat-9.0.75.tar.gz
useradd --home-dir /usr/local/tomcat --shell /sbin/nologin tomcat
cp -r apache-tomcat-9.0.75/* /usr/local/tomcat/
chown -R tomcat:tomcat /usr/local/tomcat/

πŸ–₯️ Step 4: Create systemd Service

Create /etc/systemd/system/tomcat.service:

[Unit]
Description=Tomcat
After=network.target

[Service]
User=tomcat
WorkingDirectory=/usr/local/tomcat
Environment=JRE_HOME=/usr/lib/jvm/jre
Environment=JAVA_HOME=/usr/lib/jvm/jre
Environment=CATALINA_HOME=/usr/local/tomcat
Environment=CATALINA_BASE=/usr/local/tomcat
ExecStart=/usr/local/tomcat/bin/catalina.sh run
ExecStop=/usr/local/tomcat/bin/shutdown.sh
SyslogIdentifier=tomcat-%i

[Install]
WantedBy=multi-user.target

Then reload and start the service:

systemctl daemon-reload
systemctl start tomcat
systemctl enable tomcat

πŸ”₯ Step 5: Open Firewall

systemctl start firewalld
firewall-cmd --zone=public --add-port=8080/tcp --permanent
firewall-cmd --reload

πŸ§ͺ Step 6: Download & Build the Java App

git clone -b main https://github.com/hkhcoder/vprofile-project.git
cd vprofile-project
vim src/main/resources/application.properties

Update backend service references to other VMs.

Then:

mvn install

🚚 Step 7: Deploy WAR to Tomcat

systemctl stop tomcat
rm -rf /usr/local/tomcat/webapps/ROOT*
cp target/vprofile-v2.war /usr/local/tomcat/webapps/ROOT.war
chown -R tomcat:tomcat /usr/local/tomcat/webapps
systemctl start tomcat

βœ… Result

The app should now be accessible via Nginx or directly via Tomcat (port 8080). This completes the backend service setup!


πŸ“Œ What’s Next?

In the next article (Day 28), we’ll configure the frontend Nginx web server to serve the application using reverse proxying.


πŸ“’ Follow along if you're learning DevOps step by step. Share your feedback or setup variations!

#DevOps #Vagrant #Tomcat #Java #Linux #Systemd #ManualProvisioning #DevOpsJourney


DevOps overview as a beginner

Part 27 of 50

Sharing my journey of learning DevOps as a beginner β€” covering essential tools, cloud setup, CI/CD, Docker, monitoring, and more, step by step with practical examples.

Up next

Day 28: Nginx Setup & Reverse Proxy

Nginx Setup & Reverse Proxy for Tomcat App