-
Notifications
You must be signed in to change notification settings - Fork 41
/
Copy pathDocumentation.txt
204 lines (143 loc) · 6.65 KB
/
Documentation.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
3 Tier Project
---------------------------
GitHub URL: https://github.com/KastroVKiran/3TierArchitectureApp.git
*******************************************
Steps for Setting Up the Project Infrastructure
*******************************************
1. VPC Creation
Design and create a Virtual Private Cloud (VPC) to serve as the foundation for the project infrastructure.
2. S3 Bucket and IAM Role Setup
Create an S3 bucket and upload the application code.
Set up an IAM role with the necessary permissions and attach it to the EC2 instance.
3. Database Configuration
Launch and configure an RDS instance to serve as the backend database.
4. Application Tier Setup
Deploy application-tier resources, including the configuration of an internal load balancer for traffic distribution within the tier.
5. Web Tier Setup
Provision web-tier resources and set up an external load balancer to manage incoming traffic from users.
6. SSL Certification and Domain Mapping
Generate an SSL certificate and apply it to the external load balancer to ensure secure communication.
Map the domain name to the external load balancer for public accessibility.
~~~~~~~~~~~
Step 3
~~~~~~~~~~~
Go into the following path of cloned code "application-code/app-tier/DbConfig.js" and open 'Dbconfig.js' file and change the things accordingly as shown below;
module.exports = Object.freeze({
DB_HOST: 'YOUR-DATABASE-ENDPOINT.ap-south-1.rds.amazonaws.com',
DB_USER: 'admin',
DB_PWD: 'kastro2025',
DB_DATABASE: 'webappdb'
});
The reason for having the above info is our App Servers running in Private Subnets should be able to connect to the DB, for that connectivity it is going to use these credentials provided in DbConfig.js file.
Update the above code and upload the Dbconfig.js file in the S3 bucket of 'app-tier' folder.
~~~~~~~~~~~
Step 4
~~~~~~~~~~~
Creation of App Tier Resources
4.1.
In this instance we will do the App Server Setup and DB Server Configuration. Execute the below commands;
Install MySQL
sudo yum install mysql -y
Configure MySQL Database
Connect to the database and perform basic configuration: Replace below info with your DB information
mysql -h <DB EndPoint> -u admin -p ----> Enter the Password i.e kastro2025 (this is DB password). If you couldn't connect, there is a problem with the SG of the DB.
Ex: mysql -h database-1.c380a08uukyc.ap-south-1.rds.amazonaws.com -u admin -p
Lets create a database. The database name i'm creating is "webappdb" (This is same name that you should give in DvConfig.js file);
CREATE DATABASE webappdb;
SHOW DATABASES;
USE webappdb; ----> You will see 'Database changed'
Execute the below code as a single code. Here we are creating a table with the name 'transactions'
CREATE TABLE IF NOT EXISTS transactions(
id INT NOT NULL AUTO_INCREMENT,
amount DECIMAL(10,2),
description VARCHAR(100),
PRIMARY KEY(id)
);
To verify whether table got created or not;
SHOW TABLES;
Lets insert some info into the table
INSERT INTO transactions (amount, description) VALUES ('400', 'groceries');
To verify whether the entry is really created or not
SELECT * FROM transactions;
You will see the info you have written
To come out of the DB;
exit (You will see 'ec2-user' at the end of command line and at the beginning of command line you will see 'root')
Update Application Configuration to with DB information
Update the **application-code/app-tier/DbConfig.js** file with your database credentials.
Install and Configure Node.js and PM2
curl -o- https://raw.githubusercontent.com/avizway1/aws_3tier_architecture/main/install.sh | bash
source ~/.bashrc
nvm install 16
nvm use 16 (You will see 'Now using node v16.20.2)
NVM means Node Version Manager
To run node as a service, we will install pm2
npm install -g pm2 (You will see 'found 0 vulnerabilities)
Download application code from S3 and start the application
cd ~/
sudo aws s3 cp s3://<S3BucketName>/application-code/app-tier/ app-tier --recursive
Ex: sudo aws s3 cp s3://demo-3tier-project/application-code/app-tier/ app-tier --recursive
ls ---> You will see 'app-tier' folder
cd app-tier/
npm install
ls ----> You will see 'index.js' file. We have to start that.
pm2 start index.js (You will see the status as 'online')
To verify;
pm2 list (or) pm2 status
pm2 logs (You will not see anything in red colour, everything in white colour you should see)
At the end you will see something like; http://localhost:4000
pm2 startup
pm2 save ---> To save the configuration
Verify that the application is running by executing
curl http://localhost:4000/health
It should return: This is the health check.
With this we have completed the application configuration.
4.2. Creation of Internal Load Balancer for App Tier
Goto the downloaded code folder in local system ----> Open nginx.conf file and in the end of the file you will see something like below;
#proxy for internal lb
location /api/{
proxy_pass http://[REPLACE-WITH-INTERNAL-LB-DNS]:80/;
}
Replace the LB DNS in the above
Upload the updated nginx.conf file to the S3 bucket
This one we are going to copy to the webserver in sometime.
~~~~~~~~~~~
Step 5
~~~~~~~~~~~
Creation of Web tier resources including External Load Balancer
sudo -su ec2-user (To work as an ec2-user)
cd /home/ec2-user
curl -o- https://raw.githubusercontent.com/avizway1/aws_3tier_architecture/main/install.sh | bash
source ~/.bashrc
nvm install 16
nvm use 16
aws s3 cp s3://<S3 Bucker Name>/application-code/web-tier/ web-tier --recursive
Ex: aws s3 cp s3://demo-3tier-project/application-code/web-tier/ web-tier --recursive
ls ----> You will see 'web-tier'
cd web-tier
npm install
npm run build
sudo amazon-linux-extras install nginx1 -y
Update Nginx configuration:
cd /etc/nginx (Your are in nginx path)
ls ----> You will see 'nginx.conf' file
sudo rm nginx.conf
sudo aws s3 cp s3://<S3 Bucker Name>/application-code/nginx.conf .
Ex: sudo aws s3 cp s3://demo-3tier-project/application-code/nginx.conf .
sudo service nginx restart
chmod -R 755 /home/ec2-user
sudo chkconfig nginx on
To check the output of the App, we can check using the Web-Tier-Instance public IP. But before checking lets open port no 80 with http, Anywhere IPv4, 0.0.0.0/0 ---> Save rules ----> Now paste the pubic ip of Web-Tier-Instance in new tab of browser ----> You will see the app ----> Enter the data in the app
This is about 3 tier architecture with HA and Fault Tolerance.
Delete everything once its done
First delete ASG
Next delete both LBs
Next delete both TGs
Next delete both AMIs
Next delete both Snapshots of AMIs
Next delete DB
Next delete S3 Bucket
Next delete Certificate
Next delete Route 53 record
Next delete NAT GW
Next delete Elastic IP. This came because of NATGW
Next delete VPC