Deployed Three-tier architecture
In modern application development, the three-tier architecture has become a popular choice for building scalable and maintainable systems. This architectural pattern divides the application into three logical tiers: the display layer, the business logic layer, and the data storage layer. Each tier performs a specific function and can be managed independently, providing a departure from the monolithic approach.
Cloud computing platforms, such as Amazon Web Services (AWS), offer a wide range of services to empower developers in creating robust and scalable applications. In this post, we’ll explore the utilization of key AWS services — Elastic Compute Cloud (EC2), Auto Scaling Group, Virtual Private Cloud (VPC), Elastic Load Balancer (ELB), Security Groups, and Internet Gateway — to design and deploy a fault-resistant and highly available three-tier cloud infrastructure
Three-Tier Architecture Overview:
The three-tier architecture is a fundamental design pattern for developing application A client-server design that is modular and comprises three tiers: presentation, application, and data. This is known as a 3-tier application architecture. Information is stored in the data tier, logic is managed by the application layer, and graphical user interfaces (GUIs) connect the presentation tier to the other two tiers. The three levels may or may not operate on the same physical server; they are logical and not physical.
- Presentation Tier:
- Manages the user interface and focuses on presenting information to users.
- Ensures a positive and intuitive user experience.
- Communicates with the application tier to request and display data.
2. Application Tier:
- Serves as the control center, encapsulating core business logic and application functionality.
- Facilitates bidirectional communication between the presentation and data tiers.
- Promotes modularity for adaptability and extension.
3. Data Tier:
- Houses databases or data storage systems for storing, managing, and retrieving information.
- Forms the foundation, storing user data, application data, and configuration settings.
- Communicates with the application tier through well-defined interfaces.
Key Characteristics:
- Flexibility in deployment; tiers may or may not run on separate servers.
- Modular design enhances scalability and optimization.
- Facilitates efficient, scalable, and maintainable software development
How to do :-step
Step 1: Set Up Networking
1.1 Create a VPC:
- Go to the AWS Management Console.
- Navigate to the VPC dashboard.
- Click on “Create VPC.”
- Provide a name (e.g., MyVPC), set the CIDR block (e.g., 10.0.0.0/16), and click “Create.”
1.2 Create Subnets:
- In the VPC dashboard, click on “Subnets.”
- Click on “Create subnet.”
- Choose the VPC created in step 1.1.
- Create subnets for the web server, application server, and database server, each with a unique CIDR block.
1.3 Internet Gateway and Route Tables:
- Create an internet gateway and attach it to your VPC.
- Edit the route tables for public subnets (e.g., web server subnet) to include a route to the internet gateway.
Step 2: Deploy Web Server
2.1 Launch EC2 Instance for Web Server:
- Go to the EC2 dashboard.
- Click on “Launch Instance.”
- Choose an Amazon Linux AMI or your preferred operating system.
- Configure the instance with the web server subnet and a security group allowing inbound traffic on port 80.
- Launch the instance.
2.2 Configure Web Server:
- Connect to the EC2 instance using SSH.
- Install a web server like Apache or Nginx.
- Deploy your web application code or static content.
Step 3: Deploy Application Server
3.1 Launch EC2 Instance for Application Server:
- Follow similar steps as in Step 2.1, choosing the application server subnet.
3.2 Configure Application Server:
- Connect to the EC2 instance using SSH.
- Install the necessary runtime and dependencies for your application.
- Configure your application to connect to the database (note: details configured in the next step).
- Deploy your application code.
Step 4: Set Up RDS for Database
4.1 Create RDS Instance:
- Go to the RDS dashboard.
- Click on “Create database.”
- Choose the database engine (e.g., MySQL or PostgreSQL).
- Configure the instance details, including the database name, username, and password.
- Set the security group to allow traffic from the application server.
4.2 Retrieve Database Connection Details:
- Once the RDS instance is available, note down the endpoint, database name, username, and password.
Step 5: Configure Application to Use Database
5.1 Update Application Configuration:
- Connect to the application server using SSH.
- Update your application’s configuration files with the database connection details.
Step 6: Testing
- Test the connectivity between the web server, application server, and database server to ensure everything is set up correctly.
- Access your application via the web server’s public IP or domain.
Step 7: Optional — Scaling and High Availability
- Consider setting up Auto Scaling for instances and an Elastic Load Balancer (ELB) for better scalability and availability.
Do all configuration properly Follow documentaion the link to create machine:
https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-lamp-amazon-linux-2023.html
Commands for php application server for each server
sudo dnf update -y
sudo dnf install -y httpd wget php-fpm php-mysqli php-json php php-devel
sudo systemctl start httpd
sudo systemctl enable httpd
sudo systemctl is-enabled httpd
sudo usermod -a -G apache ec2-user
exit
groups
curl http://localhost
sudo chown -R ec2-user:apache /var/www
sudo chmod 2775 /var/www && find /var/www -type d -exec sudo chmod 2775 {} \;
find /var/www -type f -exec sudo chmod 0664 {} \;
sudo dnf install php-mbstring php-xml -y
sudo systemctl restart httpd
sudo systemctl restart php-fpm
cd /var/www/html
mkdir phpMyAdmin && tar -xvzf phpMyAdmin-latest-all-languages.tar.gz -C phpMyAdmin — strip-components 1
rm phpMyAdmin-latest-all-languages.tar.gz
sudo systemctl is-enabled httpd
echo “PHP Server 1” >index.html do for php server1
echo “PHP Server 2” >index.html do for php server2
sudo systemctl is-enabled httpd
my-alb-902956905.ap-south-1.elb.amazonaws.com
after cd phpMyAdmin
mv config.sample.inc.php config.inc.php
vi config.inc.php
replace host with ALB DNS Name Entry
user data for ec2 instances
#!/bin/bash
yum update -y
yum update httpd -y
systemctl restart httpd
Application Server user data
#!/bin/bash
yum update -y
yum install -y apache-maven
yum install java-1.8.0-openjdk-devel.x86_64 -y
db-server
#!/bin/bash
yum update -y
yum install mysql
ssh-add -K dev-account.pem
ssh -A ec2-user@<dns-name>
ssh ec2-user@<ip-address-application-server>
Login to web-server OR jump server
from there login to php-app-server
install
sudo yum update -y
sudo amazon-linux-extras install -y lamp-mariadb10.2-php7.2 php7.2
sudo yum install -y httpd24 php72 mysql57-server php72-mysqlnd
sudo yum install -y httpd
sudo systemctl start httpd
sudo systemctl enable httpd
sudo systemctl is-enabled httpd
curl http://localhost
sudo usermod -a -G apache ec2-user
sudo chown -R ec2-user:apache /var/www
sudo chmod 2775 /var/www && find /var/www -type d -exec sudo chmod 2775 {} \;
find /var/www -type f -exec sudo chmod 0664 {} \;
sudo yum install php-mbstring php-xml -y
sudo systemctl restart httpd
sudo systemctl restart php-fpm
cd /var/www/html
echo “PHP Server 1” >index.html do for php server1
echo “PHP Server 2” >index.html do for php server2
mkdir phpMyAdmin && tar -xvzf phpMyAdmin-latest-all-languages.tar.gz -C phpMyAdmin — strip-components 1
rm phpMyAdmin-latest-all-languages.tar.g
Access the web app server using the URL from web
This step-by-step guide provides a practical overview of deploying a three-tier architecture on AWS. Adapt the steps based on your specific use case and application requirements. Always refer to AWS documentation for the latest information and best practices.
Remember, don’t forget to delete all resources created and configured when you are done following the steps of this article. NAT Gateways, Elastic IPs, and ALBs do have a small cost. Please, ensure you delete them especially after following this article.
Thanks for reading
I hope found this useful?
If you found this guide is useful and helpful then please do click on the button and also feel free to drop a comment
✅Reshare this with others so that it helps more people
✅Tag your colleagues and friends who you think will need this