VProfile is a multi-tier web application designed to demonstrate infrastructure automation using Vagrant and VirtualBox. It includes various services such as a web server, application server, message broker, caching service, search indexing, and a database. The project automates provisioning using Vagrant and sets up a complete working environment for deployment.
- Prerequisites
- Architecture
- Workflow
- Task Execution
- Cleaning Up Resources
- Conclusion
- Instructor
Before you start, ensure you have the following:
- Oracle VM VirtualBox - For virtualization
- Vagrant - To automate VM setup
- Vagrant Plugins - Required for network and provisioning
The provisioning process follows this sequence:
- Nginx → Web Service
- Tomcat → Application Server
- RabbitMQ → Broker/Queuing Agent
- Memcache → DB Caching
- ElasticSearch → Indexing/Search Service
- MySQL → SQL Database
Setup Order:
- MySQL (Database Service)
- Memcache (DB Caching Service)
- RabbitMQ (Broker/Queue Service)
- Tomcat (Application Service)
- Nginx (Web Service)
Create a file named Vagrantfile and add the following code:
Vagrant.configure("2") do |config|
config.hostmanager.enabled = true
config.hostmanager.manage_host = true
### DB VM ###
config.vm.define "db01" do |db01|
db01.vm.box = "eurolinux-vagrant/centos-stream-9"
#db01.vm.box_version = "9.0.48" # Commented to avoid installation errors
db01.vm.hostname = "db01"
# Port Forwarding
db01.vm.network "forwarded_port", guest: 22, host: 2222
db01.vm.network "private_network", ip: "192.168.56.15"
db01.vm.provider "virtualbox" do |vb|
vb.memory = "600"
end
end
### Memcache VM ###
config.vm.define "mc01" do |mc01|
mc01.vm.box = "eurolinux-vagrant/centos-stream-9"
#mc01.vm.box_version = "9.0.48"
mc01.vm.hostname = "mc01"
# Port Forwarding
mc01.vm.network "forwarded_port", guest: 22, host: 2207
mc01.vm.network "private_network", ip: "192.168.56.14"
mc01.vm.provider "virtualbox" do |vb|
vb.memory = "600"
end
end
### RabbitMQ VM ###
config.vm.define "rmq01" do |rmq01|
rmq01.vm.box = "eurolinux-vagrant/centos-stream-9"
#rmq01.vm.box_version = "9.0.48"
rmq01.vm.hostname = "rmq01"
# Port Forwarding
rmq01.vm.network "forwarded_port", guest: 22, host: 2204
rmq01.vm.network "private_network", ip: "192.168.56.13"
rmq01.vm.provider "virtualbox" do |vb|
vb.memory = "600"
end
end
### Tomcat VM ###
config.vm.define "app01" do |app01|
app01.vm.box = "eurolinux-vagrant/centos-stream-9"
#app01.vm.box_version = "9.0.48"
app01.vm.hostname = "app01"
# Port Forwarding
app01.vm.network "forwarded_port", guest: 22, host: 2205
app01.vm.network "private_network", ip: "192.168.56.12"
app01.vm.provider "virtualbox" do |vb|
vb.memory = "800"
end
end
### Nginx VM ###
config.vm.define "web01" do |web01|
web01.vm.box = "ubuntu/jammy64"
web01.vm.hostname = "web01"
# Port Forwarding
web01.vm.network "forwarded_port", guest: 22, host: 2206
web01.vm.network "private_network", ip: "192.168.56.11"
web01.vm.provider "virtualbox" do |vb|
# First provision with GUI enabled, then disable it after setup
# vb.gui = true
vb.memory = "800"
end
end
end
Ensure the following are installed:
git clone https://github.com/hkhcoder/vprofile-project.git
cd vagrant-setup
Run the following command to start all VMs:
vagrant up
To access a specific VM, use:
vagrant ssh <vm-name>
For example:
vagrant ssh web01
- Stop all VMs:
vagrant halt
- Restart all VMs:
vagrant reload
- Destroy all VMs:
vagrant destroy
- List running VMs:
vagrant status
- Nginx VM (
web01
) requires manual network configuration:- First Boot → Enable
vb.gui = true
inVagrantfile
- Set up the network in VirtualBox:
- Adapter 1: NAT
- Adapter 2: Bridged Adapter
- Once installed, disable the GUI (
vb.gui = false
) and runvagrant reload
.
- First Boot → Enable
-
Login to the database VM:
vagrant ssh db01
-
Verify and update
/etc/hosts
if necessary:cat /etc/hosts
-
Update OS with latest patches:
dnf update -y
-
Set repository:
dnf install epel-release -y
-
Install MariaDB package:
dnf install git mariadb-server -y
-
Start and enable MariaDB service:
systemctl start mariadb systemctl enable mariadb
-
Run MySQL secure installation script:
mysql_secure_installation
- Set root password (
admin123
) - Remove anonymous users
- Disallow root login remotely (No)
- Remove test database
- Reload privilege tables
- Set root password (
-
Create database and user:
mysql -u root -padmin123
mysql> CREATE DATABASE accounts; mysql> GRANT ALL PRIVILEGES ON accounts.* TO 'admin'@'localhost' IDENTIFIED BY 'admin123'; mysql> GRANT ALL PRIVILEGES ON accounts.* TO 'admin'@'%' IDENTIFIED BY 'admin123'; mysql> FLUSH PRIVILEGES; mysql> exit;
-
Download source code and initialize the database:
cd /tmp/ git clone -b local https://github.com/hkhcoder/vprofile-project.git cd vprofile-project mysql -u root -padmin123 accounts < src/main/resources/db_backup.sql mysql -u root -padmin123 accounts
mysql> SHOW TABLES; mysql> exit;
-
Restart MariaDB:
systemctl restart mariadb
-
Login to the Memcache VM:
vagrant ssh mc01
-
Verify and update
/etc/hosts
if necessary:cat /etc/hosts
-
Update OS with latest patches:
dnf update -y
-
Install Memcache:
sudo dnf install epel-release -y sudo dnf install memcached -y
-
Start and enable Memcache service:
sudo systemctl start memcached sudo systemctl enable memcached sudo systemctl status memcached
-
Allow external connections:
sed -i 's/127.0.0.1/0.0.0.0/g' /etc/sysconfig/memcached
-
Restart Memcached:
sudo systemctl restart memcached
-
Login to the RabbitMQ VM:
vagrant ssh rmq01
-
Verify and update
/etc/hosts
if necessary:cat /etc/hosts
-
Update OS with latest patches:
dnf update -y
-
Install EPEL repository:
dnf install epel-release -y
-
Install dependencies:
sudo dnf install wget -y dnf -y install centos-release-rabbitmq-38 dnf --enablerepo=centos-rabbitmq-38 -y install rabbitmq-server systemctl enable --now rabbitmq-server
-
Configure RabbitMQ user:
sudo sh -c 'echo "[{rabbit, [{loopback_users, []}]}]." > /etc/rabbitmq/rabbitmq.config' sudo rabbitmqctl add_user test test sudo rabbitmqctl set_user_tags test administrator sudo rabbitmqctl set_permissions -p / test ".*" ".*" ".*"
-
Restart RabbitMQ service:
sudo systemctl restart rabbitmq-server
-
Login to the Tomcat VM:
vagrant ssh app01
-
Verify and update
/etc/hosts
if necessary:cat /etc/hosts
-
Update OS with latest patches:
dnf update -y
-
Set repository:
dnf install epel-release -y
-
Install dependencies:
dnf -y install java-17-openjdk java-17-openjdk-devel dnf install git wget -y
-
Change directory to
/tmp
:cd /tmp/
-
Download and extract Tomcat:
wget https://archive.apache.org/dist/tomcat/tomcat-10/v10.1.26/bin/apache-tomcat-10.1.26.tar.gz tar xzvf apache-tomcat-10.1.26.tar.gz
-
Create Tomcat user:
useradd --home-dir /usr/local/tomcat --shell /sbin/nologin tomcat
-
Copy Tomcat files to home directory:
cp -r /tmp/apache-tomcat-10.1.26/* /usr/local/tomcat/ chown -R tomcat.tomcat /usr/local/tomcat
-
Create Tomcat service file:
vi /etc/systemd/system/tomcat.service
- Add the provided service configuration
[Unit] Description=Tomcat After=network.target [Service] User=tomcat Group=tomcat WorkingDirectory=/usr/local/tomcat Environment=JAVA_HOME=/usr/lib/jvm/jre Environment=CATALINA_PID=/var/tomcat/%i/run/tomcat.pid Environment=CATALINA_HOME=/usr/local/tomcat Environment=CATALINE_BASE=/usr/local/tomcat ExecStart=/usr/local/tomcat/bin/catalina.sh run ExecStop=/usr/local/tomcat/bin/shutdown.sh RestartSec=10 Restart=always [Install] WantedBy=multi-user.target
-
Reload systemd and enable Tomcat:
systemctl daemon-reload
systemctl start tomcat
systemctl enable tomcat
- Configure firewall:
systemctl start firewalld
systemctl enable firewalld
firewall-cmd --zone=public --add-port=8080/tcp --permanent
firewall-cmd --reload
-
Install Maven:
cd /tmp/ wget https://archive.apache.org/dist/maven/maven-3/3.9.9/binaries/apache-maven-3.9.9-bin.zip unzip apache-maven-3.9.9-bin.zip cp -r apache-maven-3.9.9 /usr/local/maven3.9 export MAVEN_OPTS="-Xmx512m"
-
Download source code:
git clone -b local https://github.com/hkhcoder/vprofile-project.git
-
Update configuration:
cd vprofile-project vim src/main/resources/application.properties
-
Build the code:
/usr/local/maven3.9/bin/mvn install
-
Deploy artifact:
systemctl stop tomcat rm -rf /usr/local/tomcat/webapps/ROOT* cp target/vprofile-v2.war /usr/local/tomcat/webapps/ROOT.war systemctl start tomcat chown tomcat.tomcat /usr/local/tomcat/webapps -R systemctl restart tomcat
-
Login to the Nginx VM:
vagrant ssh web01 sudo -i
-
Verify and update
/etc/hosts
if necessary:cat /etc/hosts
-
Update OS with latest patches:
apt update apt upgrade
-
Install Nginx:
apt install nginx -y
-
Create Nginx configuration file:
vi /etc/nginx/sites-available/vproapp
- Add the provided configuration
upstream vproapp { server app01:8080; } server { listen 80; location / { proxy_pass http://vproapp; } }
-
Activate Nginx site:
rm -rf /etc/nginx/sites-enabled/default ln -s /etc/nginx/sites-available/vproapp /etc/nginx/sites-enabled/vproapp
-
Restart Nginx:
systemctl restart nginx
To remove all virtual machines and clean up resources, execute:
$ vagrant destroy --force
In this project, we successfully set up a multi-tier web application using Vagrant and VirtualBox, provisioning various services like MySQL, Memcache, RabbitMQ, Tomcat, and Nginx. The architecture supports scalability and ensures efficient load management.
This project was completed under the mentorship of Imran Teli.