• Simple guide for load balancing and scaling on Amazon

    Let’s say you have a simple website that you are expecting to go viral due to some news story or other potential viral type publicity. If you are hosted on Amazon, you have the capability to turn your little website into a monster with just a few clicks in the Amazon web console.

    The first thing you have to know is what is powering your website. Are you running a database and is the database on the same server? We are going to assume you are running a simple database and site all on the same server.





    The first thing you will want to do is make a change to the database string of your site. If it set to localhost, you should set it to the EC2 address (or elastic IP ideally). This URL always starts ec2-IP-…amazonaws.com. When resolved internally, it will resolve to the internal IP of the instance. You will also want to adjust your security settings on the database (and possibly database user) to allow access from the other servers you are going to be starting up.

    Now you should take an image of your server. Depending on your instance type it is either an EBS backed image, or an instance store, make the appropriate image. Once complete launch another server from the image, once running check that you can reach the site at the EC2 address. You may receive a database error, if you do then you need to make sure you cleared the server in the necessary AWS security groups that you might be using. I usually add the group that all the servers are going to be in to the security group. I do this even if all the servers are in the same group which seems redundant but I have had issues when they are all in the same group without also adding the group to the allow permissions.

    Now it is time to launch the elastic load balancer. Launch the ELB and assign the 2 servers you have running now to it, you only need to set port 80 (or 443 as well if using SSL). It takes some time to get working so be patient. You will get a ELB address once launched that you can then put into your DNS as a CNAME record. If you wish to test the ELB before making any final DNS changes, once it is running you can simply put the ELB address into your web browser to confirm that it is working. Once everything is working, simply remove the A or CNAME record you use currently on your domain and replace it with the ELB address as the CNAME record.

    Now if your website is heavy on database reads and writes, you may want to consider upgrading that as well to its own dedicated server.




    Share

    Leave a reply