Deploying Multi-TierJAVA Application on AWS | SYOPS
AWS Cloud | Nginx EC2 Apache Tomcat RabbitMQ MySQL
https://github.com/aayanmtn/java-multi-tier.git
Security Groups
We need to create security groups for instances.
by clicking on Create security group
inbound rules for elb0e-sg (load balancer)
inbound rules for app01-sg (for tomcat)
inbound rules for backend-sg (for tomcat)
consist rules for rabbitmq,memcache,MySQL
Key Pair
Now we will create a new key pair by clicking on Create key pair
Insert the name.Use pem file if you are not using putty.This is very important to ssh aws instance from our computer.
Launch New EC2 Instances:
- Navigate to the EC2 Dashboard and click on “Launch instance”.
- Use the following AMIs for the instances:
- RabbitMQ (
rbmq-01
): AlmaLinux 9 AMI - Memcache (
mc-01
): AlmaLinux 9 AMI - MySQL (
db-01
): AlmaLinux 9 AMI - Tomcat Application (
app-01
): Ubuntu AMI - Assign the respective security groups created earlier to each instance.
- User Data Script:
- Paste the bash script located in the
userdata
directory of your repository into the “User data” section of the instance launch wizard. - Launch the instances.
Building the Artifacts
To build the artifact it is important to have JDK and Maven installed in your PC
- Setup Development Environment:
- Ensure JDK and Maven are installed on your local machine.
- Configure Application Properties:
- Edit the
application.properties
file, changingdigitalsierra.in
to<yourdomainname.xyz>
.
- Build the Artifact:
- Run the following command to build the artifact:
mvn install
- Upload Artifact to S3:
- Install the AWS CLI on your local machine.
- Create a new IAM user in the AWS Management Console and obtain the access key and secret key.
- Configure the AWS CLI with the obtained credentials:
- Copy code
aws configure
- Create a new S3 bucket:
- sh
- Copy code
aws s3 mb s3://<bucket-name>
Copy the build artifact to the S3 bucket:
aws s3 cp target/vprofile-v2.war s3://<bucket-name>
Create an user and get access and secret key
Use aws configure to configure cli
Now from your computer create an bucket using aws s3 mb s3://
then copy the vprofile-v2.war to the bucket use cp /target/vprofile-v2.war aws s3 mb s3://
Now access the App-01 ubuntu instance
and remove from tomcat9/webapps using this rm-rf tomcat9/webapps/ROOT.war
Copy aws s3://
Now lets Hop On to
Load Balancer and DNS
Create a new target group it falls under load balancing in EC2
Use round robin
Unified configuration and create.
Use Application Load balancer
check all mappings use HTTP port 80 And use the above target group
If you have you have acm certificate you can add https port 443
Use DNS Name to access application
You can see login using admin_vp:admin_vp