Skip to content

zhtgeneral/LoadbalanceRealtime

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

9 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ”„ LoadbalanceRealtime

✨ What this app does:
This app allows users to send and receive notifications between devices in real-time by entering and sharing messages.


πŸš€ Features

  • ⚑ Socket.io - Enables instant updates for all connected clients without page refreshes
  • 🧠 Redis - Powers rate limiting capabilities
  • βš›οΈ React + Vite - Delivers a responsive frontend with fast dev environment performance
  • 🌐 Express - Facilitates communication between frontend clients
  • πŸ§ͺ Mocha/Chai/Sinon - Provides comprehensive testing for backend API routes

🏁 Quick-start Instructions

Prerequisites

  1. Install NPM and Node.js (required for the project).

Setup

# 1. Clone the project
git clone https://github.com/zhtgeneral/LoadbalanceRealtime.git

# 2. Install dependencies
cd LoadbalanceRealtime 
cd client && npm install
cd ../server && npm install

πŸ’» Running the services

Backend Service (run from /server directory):

npm run start

This will:

  • 🐳 Launch a Redis Docker container
  • πŸš€ Start the Express backend server

Frontend Service (in a new terminal, from /client directory):

npm run dev

This will:

  • βš›οΈ Launch the React development server

πŸ§ͺ Running Tests

Integration Tests (run from /server directory)

Warning: Make sure backend server is closed, or this will not work.

npm run test:integration

This will:

  • βœ… Run all Mocha/Chai test suites
  • πŸ” Verify API endpoint functionality

πŸ—„οΈ How to deploy

☁️ Create VM instance on Oracle Cloud

  • Go to Oracle Cloud Infrastructure
  • Create Compute Instance πŸ€–
  • Change Image to Ubuntu Linux (24.04 was used) 🐧
  • Keep ARM Shape VM.Standard.E2.1.Micro 🦾
  • Create VNIC (unique for each instance) to connect compute instance to VCN (can be reused) 🌐
    • ❗Note: VCN needs an additional rule added later
  • Generate public and private key pair or reuse existing public key πŸ—οΈπŸ”‘:
    • To get a fresh set of keys:
      • Click download private key and download public key
        • Public key looks like ssh-key-<YYYY-MM-DD>.key.pub
        • Private key looks like ssh-key-<YYYY-MM-DD>.key
    • Or paste an existing public key into the input and click add
      • ⚠️ Note: This changes the SSH process slightly
  • Move the keys outside of the project location πŸ”‘βž‘οΈ
    • ⚠️ Note: The keys cannot be accessed later so do it now
  • Specify Boot Volume to 50GB πŸ“¦

Now you have created the compute instance. To make it accessible to the public, we need to add an extra rule:

  • Go to Virtual cloud networks 🌐
  • Select the VCN that was used
  • Subnets πŸ•ΈοΈ
  • Subnet name
  • Security πŸͺͺ
  • Default security list for security name
  • Security rules
  • Add Ingress Rules πŸ“²
    • Source CIDR as 0.0.0.0/0 and Desination port range as 5173

πŸ”ŽπŸŒ Verify that the VM is working

Once the compute instance is setup correctly, we can check that public IP is accessible using this command in powershell by running this command:

tnc <public-ip> -p 22

βœ… If the instance is running, it should return

ComputerName     : <public-ip>                            
RemoteAddress    : <public-ip>                           
RemotePort       : 22                                      
InterfaceAlias   : Wi-Fi                                 
SourceAddress    : <public-ip>                                                       
TcpTestSucceeded : True

⚠️ Note: It will give an error message if the compute instance is still loading.


πŸ—οΈπŸ›‘οΈ Set up SSH key security

Once the VM is verified, we can enter the VM using the SSH key. Before we can enter, we will need to change the security settings. These are the steps:

  • Right click ssh-key-<YYYY-MM-DD>.key
  • Properties
  • Security
  • Edit Group or user names
  • Remove Authenticated Users and Users from permitted users πŸ‘¨β€πŸ‘©β€πŸ‘§β€πŸ‘¦πŸ§‘ ❌
  • Make sure Administrators and SYSTEM are left πŸ”πŸ€–βœ…

βž‘οΈπŸ’» Entering the VM

❗Warning: You must complete the previous step and change the security settings on the ssh key, or else the next step won't work.

The steps to enter the VM are:

  • Run powershell in admin mode πŸ”
  • Run this command
ssh -i ./ssh-key-<autogenerated-date>.key ubuntu@<public-ip>

⚠️ Note: If you are reusing a private key when creating the compute instance, select yes so the key recognizes this public IP.

βœ… Once you have entered the VM, it should show something like this.

Welcome to Ubuntu 24.04.2 LTS (GNU/Linux 6.8.0-1026-oracle x86_64)

 * Documentation:  https://help.ubuntu.com
 * Management:     https://landscape.canonical.com
 * Support:        https://ubuntu.com/pro

 System information as of <Weekday> <Mon> <day> XX:XX:XX UTC 2025

  System load:  0.06              Processes:             120
  Usage of /:   4.0% of 47.39GB   Users logged in:       0
  Memory usage: 23%               IPv4 address for ens3: 10.0.0.186
  Swap usage:   0%

Expanded Security Maintenance for Applications is not enabled.

0 updates can be applied immediately.

Enable ESM Apps to receive additional future security updates.
See https://ubuntu.com/esm or run: sudo pro status

The list of available updates is more than a week old.
To check for new updates run: sudo apt update

Last login: <Weekday> <Mon> <day> XX:XX:XX 2025 from <IP Address>
To run a command as administrator (user "root"), use "sudo <command>".
See "man sudo_root" for details.

❌ Note: if the previous security step was skipped, you will get an error saying

Bad permissions. Try removing permissions for user: NT AUTHORITY\\Authenticated Users (S-1-5-11) on file D:/.../ssh-key-<YYYY-MM-DD>.key.
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@         WARNING: UNPROTECTED PRIVATE KEY FILE!          @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Permissions for './ssh-key-<YYYY-MM-DD>.key' are too open.
It is required that your private key files are NOT accessible by others.
This private key will be ignored.
Load key "./ssh-key-<YYYY-MM-DD>.key": bad permissions
ubuntu@<Public IP>: Permission denied (publickey).

πŸ’»πŸš€ Run the app in the VM

From here, we need to:

  • 🐳 install docker and docker-compose
  • πŸ“¦ clone the app
  • πŸš€ run the app in docker

Use these commands to run the app.

# Install Docker
sudo apt update
sudo apt install -y docker.io

# Enable and start Docker
sudo systemctl enable docker
sudo systemctl start docker

# Install Docker Compose plugin
sudo apt install -y docker-compose

# Add user to Docker group (optional: avoid using sudo every time)
sudo usermod -aG docker $USER
newgrp docker

# Clone the repository
git clone https://github.com/zhtgeneral/LoadbalanceRealtime.git
cd LoadbalanceRealtime

# Run the app in docker
docker compose up -d

βœ… If successful, you should be able to visit the app at

http://<Public IP>:5173

πŸ’‘ Additional tips after deployment

πŸ”ŽπŸ’» Verify app is running

If you use a second terminal and SSH into the VM with the first running the app, you will see this. Notice that the memory usage is higher.

Welcome to Ubuntu 24.04.2 LTS (GNU/Linux 6.8.0-1026-oracle x86_64)

 * Documentation:  https://help.ubuntu.com
 * Management:     https://landscape.canonical.com
 * Support:        https://ubuntu.com/pro

System information as of <Weekday> <Mon> <day> XX:XX:XX UTC 2025

  System load:  0.02              Processes:             146
  Usage of /:   8.6% of 47.39GB   Users logged in:       1
  Memory usage: 68%❗❗❗       IPv4 address for ens3: 10.0.0.186
  Swap usage:   0%


Expanded Security Maintenance for Applications is not enabled.

96 updates can be applied immediately.
76 of these updates are standard security updates.
To see these additional updates run: apt list --upgradable

1 additional security update can be applied with ESM Apps.
Learn more about enabling ESM Apps service at https://ubuntu.com/esm

Last login: <Weekday> <Mon> <day> XX:XX:XX 2025 from <IP Address>

πŸ”ŽπŸ—„οΈ Verify ports are correct

On a second terminal with the first running the app, run this to check if the ports are correct:

docker ps

βœ… It should return

CONTAINER ID   IMAGE                          COMMAND                  CREATED         STATUS         PORTS                                       NAMES
fcd671db7d9e   loadbalancerealtime_frontend   "docker-entrypoint.s…"   7 minutes ago   Up 7 minutes   0.0.0.0:5173->5173/tcp, :::5173->5173/tcp   loadbalancerealtime_frontend_1
1483af47b51d   loadbalancerealtime_backend    "docker-entrypoint.s…"   7 minutes ago   Up 7 minutes   0.0.0.0:3001->3001/tcp, :::3001->3001/tcp   loadbalancerealtime_backend_1
b7e50e40045c   redis:7                        "docker-entrypoint.s…"   7 minutes ago   Up 7 minutes   0.0.0.0:6379->6379/tcp, :::6379->6379/tcp   loadbalancerealtime_redis_1

πŸ“Š Monitor logs

Run this command in the VM to watch logs in real time.

docker compose logs -f

πŸ›‘ Stop Containers

Run this command in the VM to stop all containers.

docker compose down

πŸ”„ Restart Containers

Run this command in the VM to restart all containers.

docker compose up -d

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published