This project demonstrates the process of creating and configuring multiple Virtual Machines (VMs) using VirtualBox, establishing networking between them, and deploying a Node.js-based microservice on one VM. The application is a simple REST API hosted on one VM, which is accessed from another VM to simulate a distributed system.
- VM Setup: Create multiple VMs using VirtualBox.
- Networking: Establish a network to allow communication between the VMs.
- Microservices: Deploy a simple Node.js REST API on one VM.
- Distributed System: Demonstrate a basic multi-service architecture where one VM is hosting its own microservice and another VM accesses it.
- VirtualBox: Virtual machine management software.
- Node.js: JavaScript runtime to build the microservices.
- Express.js: Framework used to create the REST APIs.
- GitHub: Version control and hosting platform.
- Microservice Deployment: A single Node.js microservice is deployed on one VM, providing a simple "Hello from Microservice" message.
- Networking: VMs communicate over an internal network using HTTP requests.
- Distributed System simulation: One VM hosts the microservice, while another accesses it, simulating real-world distributed system communication.
- VirtualBox: To create and configure VMs.
- Node.js and npm: For creating and running the microservices.
- Access to GitHub: To push the code to your remote repository.
Start by cloning the project repository:
git clone https://github.com/username/repository.git
cd repositoryCreate two VMs using VirtualBox. Install Ubuntu 18.04 or later on both VMs. Ensure both VMs are connected on an internal network to allow communication between them.
SSH into VM1 and install Node.js and npm:
sudo apt update
sudo apt install nodejs npm -yVerify installation:
node -v
npm -vOn VM1:
Create a project directory and initialize a Node.js project:
mkdir microservice
cd microservice
npm init -yInstall Express.js:
npm install expressCreate server.js with the following code:
const express = require('express');
const app = express();
const port = 3000;
app.get('/', (req, res) => {
res.send('Hello from Microservice');
});
app.listen(port, () => {
console.log(`Microservice running on http://0.0.0.0:${port}`);
});Start the server:
node server.jsOn VM1, ensure the firewall allows traffic on port 3000:
sudo iptables -A INPUT -p tcp --dport 3000 -j ACCEPTOn VM2, test access to the microservice hosted on VM1:
curl http://<VM1_IP>:3000/responsefrom other VM: Hello from Microservice.
This project demonstrates how to simulate a distributed system by deploying a Node.js microservice on one VM and accessing it from another VM using an internal network. It provides insight into configuring VMs, setting up networking, and deploying applications in a multi-VM environment. Feel free to explore the repository, fork it, and make improvements or additions! Happy coding! 😊
This project is licensed under the MIT License – see the LICENSE.md file for details.