Day 27: Tomcat Setup, Code Build & Deployment
Tomcat Setup, Code Build & Deployment using Vagrant VMs

π 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




