2

I installed Wordpress using EC2. I created a Load Balancer by creating image (AMI) then adding both Wordpress1 and Wordpress2 on Load Balancer. But I'm still getting database error and have to restart the instances. If I'd like to make 4 instances as Load balancer, are the steps the same? because I saw a "Number of Instances" option when I launched an AMI. Default value is 1. I'm not sure if I should enter 3 or 4 to create multiple instances in one click.

Also, if I update on Wordpress1 instance, will the updates show if the domain will load Wordpress2 instance?

Mara Ang
  • 23
  • 1
  • 3
  • Have you moved the database to a separate instance, and put the file storage on s3 or an nfs volume shared by another instance? – datasage Sep 30 '13 at 14:55
  • I did it by using this guide: http://harish11g.blogspot.com/2012/02/configuring-aws-elb-console.html , so I'm not sure with the file storage. >. – Mara Ang Sep 30 '13 at 14:59

2 Answers2

3

If you want to launch multiple instances and a database etc, you should consider using AWS CloudFormation. CloudFormation is just a big json string that contains the configuration of your environment, including the servers, autoscaling, access, register with the loadbalancer, etc.

See http://aws.amazon.com/en/cloudformation/ for more details.

There is already an example template for wordpress including a database and autoscaling groups (example wordpress template)

However like datasage mentioned you will need to make adjustments to wordpress to make it working in a multiserver environment.

The "problem" with multiserver environments is that if you upload a file or in your case upgrade wordpress, it will only happen on one server, which could be terminated at any point. Furthermore the upgrade could contain changes in the database structure and then its getting complicated.

If you are building something in the cloud you should always keep in mind that every service you build, in you case the frontend webservers and the database should be allowed to fail without interrupting your service.

Another point is, that you should avoid doing stuff by hand, automation is the key. An environment where you need to link your server by hand to a loadbalancer is not very useful in the cloud where servers are continuously terminated, rebooted and exchanged.

For you webservers you can use "autoscaling groups" to get this behavior. If you are using autoscaling groups and a server is terminated or considered unhealthy, a new one will be started automatically and registered with the loadbalancer as soon as it is considered as healthy.

For your database amazon offers for rds multi AZ environments which provide a automatic failover.

Applying upgrades in the cloud can be a tricky and there are different ways to do this. for example using a shared NFS mount with the code base, git deployments or the way you already started: creating a new AMI for every upgrade and then replacing the servers. There are a lot options and they all have their benefits and drawbacks.

As far as i understand you use-case the cloud is maybe not the right choice at the moment.

Normally hosting a small business in the cloud is much more expensive than using a single server. You will only save money if you need like 20 servers in the evening and only 2 or 3 for the rest of the day. Of course there are a lot more points to consider but that would be to much.

Justus Krapp
  • 1,116
  • 9
  • 10
  • I'm kind of torn choosing between RDS or CLoudFormation. If I chose any of the two, do I need to terminate my wordpress instances on EC2? – Mara Ang Oct 01 '13 at 03:13
  • Well RDS is the Database service from amazon, so in you case you rds instance is a maysql server. cloudFormation is a tool to configure you environment. where you say i want 4 webservers of this size, with this ami and they should be connected to this loadbalancer. You should rethink about your current infrastructure. Ask you self some question. What will happen if a webserver dies, what happens if the database fails etc. If you decide to rearrange your infrastructure you will have to terminate your existing instances. But the termination of a instance in the cloud should be daily business – Justus Krapp Oct 01 '13 at 07:46
  • What I want to happen is that, if Wordpress will show a database error, the instance will autoreboot itself. Because even when using LoadBalancer, I still get Database Error (maybe because of bandwidth from the free tier). I really don't know how to avoid getting Database Error. – Mara Ang Oct 01 '13 at 08:08
  • what kind of database errors? when do they appear, can u give us an example? – Justus Krapp Oct 01 '13 at 08:17
  • It says "error establishing a database connection" with white background. A reboot will fix it every time. I think it has something to do with the bandwidth. I have hosted my image files on dropbox at the moment since I only have few images. – Mara Ang Oct 01 '13 at 10:23
  • bandwidth is not be limited by the free usage tier. The problem must be somewhere else. can you check the log files, that would help – Justus Krapp Oct 01 '13 at 10:51
  • I can't imagine a situation in which using a shared NFS mount has any benefits in this day and age. :-P – Scott A May 29 '14 at 15:04
1

Autoscaling in ec2 is horizontal scaling. Which means that instances are added as your infrastructure scales up. This in contrast to vertical scaling where the a single instance is given more resources.

In order to use this effectively, each instance cannot store data that may be needed by other instances. The most common requirement is the database which will need to exist on its own instance outside of the autoscaled instances. You could use RDS for this.

Wordpress also stores file uploads, plugins and themes within the wp-content folder within the wordpress install. By default, if you upload a file, it will be stored on one instance but not any of the others. You could store everything on an NFS volume shared by one of the instances, or you could try a plugin like this: http://wordpress.org/plugins/wp2cloud-wordpress-to-cloud/

datasage
  • 19,153
  • 2
  • 48
  • 54
  • If I use the plugin, do I also need to use RDS? Or just S3? moreover, do I need to delete the LoadBalancer and use only one instance? sorry, I'm very new to AWS, and I just read about EC2 a month ago and decided to use it for our wordpress website. – Mara Ang Oct 01 '13 at 03:14