3 Tierproject

Download as pdf or txt
Download as pdf or txt
You are on page 1of 32

3-Tier Architecture: Deployment of Java-Springboot-App

on MySQL Database With Load Balancer and Auto Scalling


Goup

Project Overview:

Project Name: Healthcare

Language use: Java

Database: MySQL

Architecture: 3 Tier

Domain: Health care

Modules: Patient, Doctor, Admin

Patient - Registration, Login, Online Appointment, Cancel


Appointment, manage profile

Docter: Login, view appointment, manage profile

Admin: Add Doctor, Department Management, Reports

Resources Needs for infrastructure


1. VPC

2. SUBNET (PUBLIC & PRIVATE)

3. INTERNET GATEWAY

4. ROUT TABLE (CONNECT WITH IGW)

5. NAT GATEWAY

6. ROUT TABLE (CONNECT WITH NAT)

7. NACL (INBOUND & OUTBOUND RULE)

8. SECURITY GROUP (INBOUND &OUTBOUND)

9. EC2 INSTANCES (APP-SERVER, JUMPBOX, DB-SERVER)

10. Load Balancer


11. Target Group

12. Auto Scaling Group

Architecture:

Detailed Steps:

1. Creating VPC:
 VPC: VPC stands for Virtual Private Cloud. It's a service provided
by cloud computing platforms like Amazon Web Services (AWS),
Google Cloud Platform (GCP), or Microsoft Azure that allows
users to create a logically isolated section of the cloud where
they can launch resources like virtual machines, databases, and
storage networks.
AWS Account -> VPC -> Create VPC(healthcare-vpc)->
2. Creating Subnets:
AWS subnets are associated with a specific availability zone
within a region. Each subnet is tied to a particular availability
zone, providing a way to distribute resources across different
zones for fault tolerance and high availability.

Requirement: Create 2 Subnets one is for Application servers and


another is for Database. According to our requirement the
application servers to be created at public subnet as these
servers can be accessed by public people. The DB server to be
created at private subnet as it contains data.
Subnet1(public): AWS Account Subnet Create
Subnet(healthcare-public-subnet-1)

Subnet2(private): healthcare-private-subnet-2
Subnet1(private): AWS Account Subnet Create Subnet(healthcare-
private-subnet-2)
Subnet2(private): healthcare-public-subnet-2
Subnet1(public): AWS Account Subnet Create Subnet(healthcare-
public-subnet-3)
Create Internet-Gateways:
In Amazon Web Services (AWS), an internet gateway is a crucial
component that allows communication between instances in your VPC
(Virtual Private Cloud) and the internet. It acts as a gateway or
entry/exit point for network traffic between your VPC and the internet.

Requirement : We need to attach Internet Gateway with the public


subnet of VPC to have internet access between resources present in
public subnet and Internet.
Create IGW: Healthcare-igw

Create Route Tables:

In AWS (Amazon Web Services), a route table is a key component of


the Virtual Private Cloud (VPC) networking setup. It's essentially a set
of rules, or a table, that defines how network traffic should be directed
within a VPC.

Purpose Of Rout Table:

Route tables define the paths for network traffic within a subnet or
Virtual Private Cloud (VPC), determining how data is directed. They
facilitate communication between subnets, control outbound traffic,
and are crucial for effective network routing in cloud environments.
AWS DashboardSearch Bar (search Rout Table)Create Route Table

Associate Subnets and Add Rules:


After creating Rout Table, go to the subnet associations and associate
with required subnet.

Route TableSubnet AssociationAssociate healthcare-public-


subnet-1
Route TableEdit RouteAdd Rout (0.0.0.0/0)Connect Igw

Create NAT Gateway:


A Network Address Translation (NAT) Gateway is a managed AWS
service that allows private subnet resources to initiate outbound
internet traffic while remaining hidden from the public internet.
Create NAT gateway and connect with healthcare-public-subnet-1 and
allocate elastic ip

Nat gatewaySubnet(healthcare-public-subnet-1)Allocate Elastic


ipCreate NAT gateway

Create Route Table for NAT Gateway:


Here we create a route table and associate with healthcare-private-
subnet-2 after association add rout (0.0.0.0/0) with Nat gateway.

Route TableName rtbConnect VPC


Route TableSubnet AssociationAssociate All Private-Subnet

Route TableAdd route (0.0.0.0/0)Target (Nat gateway)


After Configuring the required resoureces under VPC (Subnets,Internet-
gateways,NAT-gateways,Route Tables).We need to create 4 EC2-
Instances under the VPC and deploy the Spring-boot Applications.

Create Security Group:


It performs the function of a virtual firewall, managing the inbound and
outbound traffic for one or more Amazon EC2 instances or other AWS
services within a VPC.Security group have two rule i.e. ,

1.Inbound Roule: These outline the types of traffic that are permitted to
use the resources. It serves as a virtual firewall, controlling the traffic
going in and coming out of a VPC for one or more Amazon EC2
instances or other AWS services.

2.Outbound Rule: These regulate the traffic that is permitted to depart


from the resources. The destination for incoming traffic is dealt with by
outbound rules. They may be forwarded to an alternative Security
Group, a CIDR block, a single IPv4 or IPv6 address, or all three.

Four Security Groups need to be created i.,e app-server-Sg, Jumpbox-


Sg, Database-Sg, Loadbalancer-Sg.

Same process for all Security Group only difference in rule(inbound and
outbound)
Create EC-2 instances:
EC2 offers a variety of instance types optimized for different use cases,
including compute-optimized, memory-optimized, and storage-
optimized instances. Users can choose instances with the right balance
of CPU, memory, storage, and networking capabilities.

Using Three EC-2 Instances (On Public-Subnets):


Here 3 EC2 Instances

1. App-server-vm1

App-server-vm1 is a virtual machine instance, likely representing an


application server, within a cloud-based infrastructure.

2. Jumpbox-vm

A jumpbox virtual machine, also known as a bastion host, provides a


secure entry point for accessing and managing other machines within a
network.

3. Date-base-vm

database-vm1 is a virtual machine instance designed to host and


manage database services within a cloud environment.

 Open AWS dashboard the go to search bar and search EC2 then
click on EC2 service then create EC2 instance.
InstanceLaunch Instance Name Application and OS
ImagesInstance typeKey PairNetwork Setting(select vps,
Select subnet, Auto-assign public IP, Security group
name – required)Launch
Same procedure applies on rest of three instances.

Lunch vm in the Terminal:


After creating instance then copy the public Ip of jump box vm
and open the terminal like mobaXterm & connect with database-
vm then set of the MySQL dB server.
Procedure To Connection of Database-vm And Set Up of
MYSQL Databse:
 Open GitHub spring-boot-db. repo then go to
srcresourcesapplication. properties
(spring.datasource.url=jdbc: mysql://mysqldb:3306/mydb)put
your private ip of database-vm
 Open jumpbox-vm
 Go to root user (sudo su -)
 Update machine (apt-get update)
 Open vi key.pem

 Open key on word pad copy & paste on vi editor


 Give permission (chmod 400 vm2-key.pem)
 Write ssh command to connect to database machine (ssh -i
"vm2-key.pem" [email protected])
 Install mysql(apt-get install mysql-server
 Install mysql client (apt-get install mysql-client)
 Enter into mysql server (mysql -u root -p) & give the password
root
 Create database
 After enter into MySQL server then apply MySQL commands
 show databases;
 create database mydb;
 use mydb;
 After creation of database then exit form MySQL and configure
the bind_Address.
 After configure the bind_adress then enter into MySQL server
 Restart the services (service mysql restart & systemctl restart
MySQL)
 Create user (MySQL> CREATE USER 'root'@'%' IDENTIFIED BY
'root')
 Grant all privileges (GRANT ALL PRIVILEGES ON *.* TO
'root'@'%' WITH GRANT OPTION;)
 After grant privileges then flush privileges(FLUSH PRIVILEGES;)
This is procedure to set up the MySQL database.

Procedure To Set Up App-server-vm1 & App-server-vm2:


 Open App-server vm as same as jumpbox vm
 Go to root user (sudo su -)
 Update the system (apt-get update)
 Install java (apt-get install openjdk-8-jdk)
 Go to opt (cd /opt)
 Install maven (wget https://dlcdn.apache.org/maven/maven-
3/3.9.6/binaries/apache-maven-3.9.6-bin.tar.gz)
 You will get a tar file & untar this file (tar -xvzf tarfile)
 Check list(ls) then rename untar file (mv untar file maven)
 Go to your GitHub repo copy the java-springboot-db url
 Clone it in your machine (git clone url)
 Go to your java-springboot-db folder
 Create Artifact (/opt/maven/bin/mvn clean package)
 Check list (ls) here we get a .war or .jar file
 Give the java command (java -jar .war) file
 After that take public ip of app-server then check in your
browser with port 8080
After completion of all app-server-vm set up then we will use
this app sever as service.

Procedure to making app-server-vm as service:


 Stop the spring boot app which is running in foreground.
 After Stop this app then go to root user and then enter to this
(cd /etc/systemd/system/)
 Then create a file i. e.; vi (mybootapp.service) and wriet inside
this file
 [Unit]
 Description=My Spring Boot Application
 After=syslog.target
 [Service]
 User=ubuntu
 ExecStart=java -jar /opt/ aws-project/target/springboot-app-
1.0.war
 SuccessExitStatus=143
 [Install]
 WantedBy=multi-user.target
 After write this script we should run this four command to make
spring-boot-app as a servise i. e.;
 ( systemctl daemon-reload
 systemctl start mybootapp
 systemctl enable mybootap
 systemctl status mybootapp)
Create AMI (Amazon Machine Image):
Amazon Machine Image (AMI) is a pre-configured template that
contains the software configuration (operating system, application
server, applications, and related configurations) required to launch an
instance in Amazon Elastic Compute Cloud (EC2). It's like a snapshot of
a virtual machine that can be used to create multiple instances with
the same configuration.

Before we are set the auto scalling group first of all we create a Ami of
app-server-vm.

App-server-vmActionimage & templatescreate imageimage


nameImage description(optional)create image.
Create Launch Template:
Launch Templates reduce the number of steps required to create an
instance by capturing all launch parameters within one resource. This
makes the process easy to reproduce.

After creation of AMI then we proceed to create launch template using


this AMI.

EC2 DashboardLaunch TemplateLT nameAMIInstance


typeKey pairNetwork setting(only SG)Create
Create Load Balancer:

In AWS, a load balancer helps distribute incoming network traffic


across multiple targets, such as EC2 instances, containers, IP
addresses, or Lambda functions. This distribution ensures no
single resource gets overwhelmed, thereby enhancing the fault
tolerance and availability of your applications.

In load balancer there are 4 main resources are present e.g.,


1. Fault Tolerance: A resilient load balancer is designed to tolerate
faults, errors, or failures without compromising its core
functionality.
2. Redundancy: Resilient load balancers often employ redundancy
by having multiple instances or nodes. If one node fails, another
can take over to ensure uninterrupted load balancing.
Redundancy can be implemented at both hardware and software
levels.
3. Health Checking: Load balancers continuously monitor the health
of the backend servers to which they distribute traffic. Health
checking involves periodically verifying the availability and
responsiveness of each server.
4. Auto-Scaling Integration: When there is a sudden increase in
traffic, auto-scaling can dynamically add more backend servers
to handle the load. The load balancer then adjusts its distribution
accordingly.
 Before creating load balancer first, we create the Target
group.

Create Target Group:


In Amazon Web Services (AWS), a "target group" refers to a
component used in the Elastic Load Balancing (ELB) service.
Target groups are essentially groups of resources or
instances—such as EC2 instances or IP addresses—where
incoming traffic is routed based on the rules and conditions
defined in the associated load balancer.

Aws (search bar)Target groupBasic configurationRegister your


target
Create Load Balancer:
After creating Target Group then go to Load Balancer.

AWS (search bar)Load balancerCreate Load balancerload balancr


type (choose application load balancer)Basic ConfigurationScheme
(internet facing)Network mappingSecurity Group Listeners and
routing
After creating Load Balancer then copy the dns address then paste it in
your browser and health check on your Target Group
Create Autoscaling Group:
In Amazon Web Services (AWS), a "target group" refers to a
component used in the Elastic Load Balancing (ELB) service. Target
groups are essentially groups of resources or instances—such as EC2
instances or IP addresses—where incoming traffic is routed based on
the rules and conditions defined in the associated load balancer.
Using Of ASG:
The most common way to scale is based on CPU usage, is by defining a
threshold to specify when to add new instance and when to terminate,
however, you can configure other criteria, for example, memory usage,
disk IO, and even you can define your custom metric like a number of
the webserver requests. so it depends on where you see the bottleneck
on your environment on high load.

Go to EC-2 dashboard then go to search bar to search auto scaling


group

Create ASGChoose launch templateNamelaunch


template(customize) Choose instance launch options Configure
advanced options – optional Configure group size and scaling –
optional ReviewCreate ASG
After creating the Auto Scaling Group then go to your load balancer
and copy the dns link and paste in your browser and check your
output. After that you go to your Target Group check the heath of your
server. This the all set up of the load balancer with Auto Scaling Group

You might also like