Skip to content

RaihanIIUC/Backend-Deploy-Using-VPC-With-Load-Balance

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

VPC setup

we will start preparing our vpc by picture by picture : when ever you enter into google cloud console , you will see some thing like , we called it sandbox :

sandbox-front

Steps :

1. create vpc

vpc-front

vpc-form-filled

after filling this vpc form , it will take some time , if everything ok , then you have a vpc for you .

2. create NAT

nat-form-filled

Now we are ready with our VM to GO.

filled the form like avobe picture , but you can change as your needs. nat-router--form

with inside it , you need a router for your nat , add it as picture describes.

3. VM For Backend

first we create a vm template instance with private ip configuration

vm-private-ip-template-filled

we showed how to filled it . the main difference of it with pubic ip ones is External ip : Network subnet tab

Setup Backend in VM

clone this project locally

  • clone this project git clone address
  • cd backend-deploy-in-vpc-with-load-balance
  • go to : https://github.com/nodesource/distributions , take binary 16 version and install
  • node --version
  • sudo corepack enable will enable yarn and other npm related corepack.
  • yarn add nodemon
  • yarn run dev

setup database

  • sudo apt update
  • sudo apt install default-mysql-server
  • sudo systemctl start mysql
  • sudo systemctl enable mysql
  • sudo mysql_secure_installation
  • mysql -u root -p

if any issue with mysql :

sudo mysqld_safe --skip-grant-tables & mysql -u root sudo systemctl stop mysql sudo systemctl start mysql

setup redis

  • sudo apt install redis
  • redis-cli --version

test primsa database connection

Load Balance Setup

vpc-public-ip-template

we create a public ip available vm instance template so that we can make a load balance cloing the publically setted template.

Inside LoadBalance

cd /etc/nginx ls sudo nano nginx.conf change this conf file as needed :

`events { # empty placeholder }

http {

server {
    listen 80;

    location / {
        proxy_pass http:https://frontend-raihan;
    }

    location /api/ {
        rewrite ^/api/(.*)$ /$1 break;
        proxy_pass http:https://backend-raihan;
    }
}

upstream frontend-raihan {
    server 11.10.10.12:80;
    server 13.10.10.14:80;
}

upstream backend-raihan {
    server 10.10.0.5:8000;
    server 11.10.10.6:8080;
}

}`

location /api/ { rewrite ^/api/(.*)$ /$1 break; proxy_pass http:https://backend-raihan; }

upstream backend-raihan { server 10.10.0.5:8000; server 11.10.10.6:8080; } set two backend there so that whenever you have huge request it will auto transfer user to other one.

if lag / cache issue :

sudo nginx -s reload

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published