Multi-tier Architecture on AWS
jicoing
Posted on July 18, 2021
About
Build a multi-tier architecture project with various AWS services for real time environments.
- R53 - To create record sets within hosted zones.
- VPC - To create subnets, internet gateway, route tables, security groups.
- SNS - For notification services.
- ELB - For load balancing.
- ACM - For SSL certificates.
- EC2 - Instances with elastic IP and Auto Scaling group attached.
- RDS - Master database with multi - AZ configuration.
Steps :
1. Public and private subnets, IGW, NAT Gateway,etc.
VPC
Public Subnet - 1
Public Subnet - 2
Private Subnet - 1
Private Subnet - 2
Created
IGW
Attached to VPC
Private Route table for VPC
NAT Gateway with attached Elastic IP
Associate private subnets with NAT Gateway
Associate NAT gateway to Private RT
Attach private subnets to Private RT
Attach IGW to Public RT
VPC setup completed!
2. Create EC2 instance with Userdata (Bootstrapping) script.
Amazon Linux 2 -T2 micro
VPC - Komla-VPC
Create IAM role for EC2 service for S3 access
Attach it to the EC2 instance
Create SNS topic
Add subscription email
EC2 setup complete!
3. Create RDS Security Group and RDS subnet group with Private Subnets.
Create security group
Provided access to only webserver SG
Create Database
Type - MySQL
VPC - Komla-VPC
SG - Security group for incoming traffic from EC2 on port 3306.
Instance - db.t2.micro
Database created!
Create ELB
VPC - Komla-VPC
Spread across Public subnets
Create SG for load balancer
Health check parameters
Add EC2 instance
ELB created!
Apache server operating. EC2 instance healthy!
4. Launch RDS instance with Multi-AZ.
5. Install WordPress.
Latest version of WordPress requires atleast php 5.6. Amazon t2 micro comes with php 5.4 standard. To bypass this issue I installed php 7. Refer.
sudo amazon-linux-extras install -y php7.2
sudo service httpd restart
Installing Wordpress: Official tutorial
wget https://wordpress.org/latest.tar.gz
Extracted the downloaded package from wordpress with
tar -xzf latest.tar.gz
Moved the contents of wordpress directory to /var/www/html
cd /etc/httpd/conf
edit httpd.conf
Search for "AllowOverride None" changeNone
toAll
.
It is in/var/www/html
directory.
Change permissions on html directory.
chown -R apache:apache /var/www/html
.
Wordpress opens on the Public IP of EC2 instance!
http://18.***.161.241/wp-admin/setup-config.php
Check whether RDS is accessible via EC2 instance.
After configuring the dbname,username, password, hostname the wordpress application is up and running on Public IP of EC2 instance on the browser!
6. Create Route53 hosted zone to map with domain.
The ELB DNS is configured as an A record for the domain name
wordpress.komlalebu.com
.
7. Create AMI for EC2.
8. Create ELB.
The EC2 instances are now accessed with the ELB DNS.
9. Create launch configuration from AMI.
10. Create ASG for launch configuration.
VPC - Komla-VPC
Subnets - Public subnets
ELB - Komla-ELB
Desired - 2 instances
Minimum - 1 instances
Maximun - 2 instances
11. Health Check and fault tolerance.
Terminated all instances created by Auto Scaling for testing.
Health check failed and a new instance was created from AMI with ASG.
Notification received in mail whenever instances are terminated or launched.
Website up and running within minutes of server failure!
Posted on July 18, 2021
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.