Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to setup Java application (tomcat and mysql) on Amazon AWS with Auto Scaleup and Load balancers? [closed]

My current scenario is that I have a Java EE application built on Struts 2.0 and running on tomcat + mysql server. The app is currently hosted on Virtual Private Server with 2GB RAM and 60GB disk. However the application usage increases by 10 to 20 times during the peak hours resulting in crashing of Tomcat and MySQL server.

I started looking for alternatives and found Amazon's EC2 as the best match. I have successfully set-up the free tier Micro instance of RHEL AMI and installed Tomcat + MySQL on the machine. I also read about EBS, Load Balancers, Auto Scale, Cloud Watch and related stuffs on Amazon website.

This is my primary objective which I want to achieve via AWS:

  • Set up two EC2 instance on Amazon (Primary and Secondary)
  • The secondary instance will be inactive during most of the day
  • During the peak hours, the secondary instance should wake up automatically
  • The Load Balancer will then start routing traffic to both the server depending upon availability
  • After the traffic reduces, the secondary server should be de-activated automatically

I have the following dumb questions :)

  • How will MySQL data be shared between both the EC2 instance? Can I install MySQL on an EBS volume and mount this volume on both the EC2 instance, at the same time? Will this solve my existing MySQL problem of : Too many connections, which I get alot on my current VPS during peak hours?

  • How do I share uploaded files and images on both the EC2 instance? Will I have to store these files on the external EBS volume (outside my Tomcat WebApps Directory)?

  • Can I keep my complete project folder in the External EBS volume and have both the EC2 tomcat instance do a virtual mapping? Kindly let me know the pros and cons of it.

Also, some good tutorials on Clustering tomcat on EC2, session management, AWS auto scaling and load balancers will be of great help.

like image 405
Gaurav Srivastava Avatar asked Oct 21 '22 02:10

Gaurav Srivastava


1 Answers

Well, I am not really experienced at building AWS structures yet, but I will try to help.

1) You cannot share EBS volumes through EC2 instances, you will have to use a web-service or RDS to this scenario... Maybe it will be easier to pay a little more for a better instance while you work on the changes, also, Load Balancer adds a little more expences on your system, use aws calculator to check if it worth.

2) For the files I suggest you to use S3, api is really simple, no tricks, good speed and a lot cheaper than storing images on EBS, just save the link on database and you are good, access from anywhere.

3) As I mentioned on the first answear, you cannot share the EBS volume, so, you will need two equals instances.

Also, take a look at this option: http://aws.amazon.com/pt/elasticbeanstalk/ It is a really simple way to start anything at aws.

like image 76
Pozzo Apps Avatar answered Oct 23 '22 18:10

Pozzo Apps