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
Subscribe to my newsletter
Read articles from Shaharyar Shakir directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
