🔧 AI Nachrichten Debian is Voting on Whether to Allow AI-Assisted Contributions(23.08.2026 um 09:34 Uhr)
🔧 AI Nachrichten The Linux Kernel Is Approaching 2,000 CVEs Per Release(29.08.2026 um 20:00 Uhr)
⚠️ Malware / Trojaner / VirenCitrix Adds a Linux-Powered Escape Hatch For Compromised Windows PCs(30.08.2026 um 17:34 Uhr)
🔧 AI Nachrichten Debian is Voting on Whether to Allow AI-Assisted Contributions(23.08.2026 um 09:34 Uhr)
🔧 AI Nachrichten The Linux Kernel Is Approaching 2,000 CVEs Per Release(29.08.2026 um 20:00 Uhr)
⚠️ Malware / Trojaner / VirenCitrix Adds a Linux-Powered Escape Hatch For Compromised Windows PCs(30.08.2026 um 17:34 Uhr)

🔧 Programmierung 🕛 vor 1 Jahr 5 Min Lesezeit
0

How to Create and Configure a Multi-VM Vagrant Setup for Web and Database Servers

↗ Quelle (dev.to)
🗣️ Stimme:

Introduction



Virtualization is an essential tool for developers and system administrators. It allows you to simulate multiple servers on a single physical machine, helping you test, develop, and simulate real-world environments. Vagrant is a popular open-source tool that makes it easy to manage virtual machines (VMs) and set up reproducible development environments.



In this article, we’ll walk through how to create a multi-VM setup using Vagrant. Our goal is to set up a basic infrastructure with two web servers (web01 and web02) and one database server (db01). We’ll also show you how to automate the provisioning of these VMs using a simple shell script.



Prerequisites

Before we get started, make sure you have the following tools installed:




  • Vagrant: A tool for building and managing virtualized environments.

  • VirtualBox: A virtualization platform that Vagrant uses to create and manage virtual machines.

  • Git (optional): For version control and saving your project to GitHub.



You can install both Vagrant and VirtualBox from their official websites:







Project Overview

In this setup, we will create:




  • 3 VMs:



    • web01: A web server running Ubuntu 20.04.


    • web02: Another web server running Ubuntu 20.04.


    • db01: A database server running Ubuntu 20.04, with MySQL installed and provisioned automatically.





All VMs will have private IPs so they can communicate with each other within the network.



Step-by-Step Guide




  1. Setting Up the Vagrantfile
    The core of the setup is the Vagrantfile, a configuration file where you define your virtual machines and their settings. Below is the full code for the Vagrantfile:



CODE
Vagrant.configure("2") do |config|
config.vm.box = "ubuntu/focal64"

config.vm.define "web01" do |web01|
web01.vm.hostname = "web01"
web01.vm.network "private_network", ip: "192.168.56.41"
web01.vm.provider "virtualbox" do |vb|
vb.memory = "512"
vb.cpus = 1
end
end

config.vm.define "web02" do |web02|
web02.vm.hostname = "web02"
web02.vm.network "private_network", ip: "192.168.56.42"
web02.vm.provider "virtualbox" do |vb|
vb.memory = "512"
vb.cpus = 1
end
end

config.vm.define "db01" do |db01|
db01.vm.hostname = "db01"
db01.vm.network "private_network", ip: "192.168.56.43"
db01.vm.provider "virtualbox" do |vb|
vb.memory = "1024"
vb.cpus = 2
end

db01.vm.provision "shell", inline: <<-SHELL
sudo apt-get update -y
sudo apt-get install -y wget unzip mysql-server -y
sudo systemctl enable mysql
sudo systemctl start mysql
echo "Database server setup completed."
SHELL
end
end





Explanation of Key Sections:





  • config.vm.box = "ubuntu/focal64": This sets the base VM image to Ubuntu 20.04 (Focal Fossa).


  • config.vm.define "web01" and config.vm.define "web02": These sections define the web01 and web02 VMs, assigning them IPs and setting up VirtualBox memory and CPU options.


  • config.vm.define "db01": This defines the database server, assigns an IP, and provisions it by installing MySQL.



2. Running the Vagrantfile

Once you have the Vagrantfile in place, navigate to the directory where it is saved and run the following command:




CODE
vagrant up






output



To check if MySQL is running, you can use:




CODE
mysql --version






output



It means web01 can communicate with web02. You should also repeat the process by logging into web02 and pinging web01:




CODE
   ping 192.168.56.41






output





your web servers can reach the database server since the pings are successful.



Testing MySQL on db01




  1. Check if MySQL is running:
    SSH into db01 and check if MySQL is running:




CODE
   vagrant ssh db01
sudo systemctl status mysql






output





This output shows the MySQL version that is installed on db01.



Conclusion

In this tutorial, we’ve created a simple multi-VM environment using Vagrant, consisting of two web servers and a database server with MySQL. We also automated the database server’s setup with a shell provisioning script.



By using Vagrant, you can easily replicate this environment, experiment with different configurations, and quickly tear it down when you're done. This setup is perfect for testing, learning, or developing web applications in isolated environments.

Vollständiger Original-Bericht
Ausführliche Details, Code-Beispiele & Hersteller-Stellungnahme auf dev.to.
↗ Original-Artikel auf dev.to lesen
Wie bewertest du diesen Beitrag?
1 Klick Feedback
Teilen mit Netzwerk & Team:

Community-Analysen & Experten-Meinungen 0

Verfasse deine eigene Analyse, teile Workarounds oder diskutiere diesen Vorfall im Blog.
Noch keine Community-Analyse verfasst. Markiere einen Textabschnitt oder klicke oben auf Eigene Analyse verfassen“!
Community Pulse: Relevanz-Einschätzung
1 Klick Experten-Votum
🔴 Akute Relevanz 0%
🟡 In Evaluierung 0%
🟢 Keine Auswirkung 0%
Spannende Innovation 0%
Verwandte Story-Cluster & Quellen (Vektor-KI)
Port 8095 Engine
1 Quelle
Debian is Voting on Whether to Allow AI-Assisted Contributions
1 Quelle
The Linux Kernel Is Approaching 2,000 CVEs Per Release
1 Quelle
Citrix Adds a Linux-Powered Escape Hatch For Compromised Windows PCs
Ähnliche Beiträge
🔍 Verwandte News

Auch interessante Nachrichten How to Create and Configure a Multi-VM Vagrant Setup for Web and Database Servers

Thematisch verwandte Begriffe: Create, Configure, MultiVM, Vagrant · 6 Treffer

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...