Auto-scaling
Web Consultancy
• Only pay for capacity we use
• Handle huge traffic peaks
• Automatically recover from failure
Slide 15
Slide 15 text
Web Consultancy
When your traffic increases, our robot will
automatically create a new web server for
you.
Slide 16
Slide 16 text
• Cloud hosting provider
• Various services
• We’ll be using Elastic Load
Balancers, EC2 (Elastic Compute
Cloud) and RDS (Relational
Database Service)
What is AWS?
Web Consultancy
Slide 17
Slide 17 text
Auto-scaling
Web Consultancy
• Create new web servers
• Use ELB load balancer
• Use Amazon RDS database which
will in this example will need to be
large enough to handle our traffic
peaks
Slide 18
Slide 18 text
Auto-scaling
Web Consultancy
• We’ll need a way of setting up web
servers
• And we’ll need a way of installing
our code on to them
Slide 19
Slide 19 text
• Configuration management tool
• Install packages
• Ensure services like Apache are running
• Write out configuration files from
templates
• Restart services when templates
change
What is Chef?
Web Consultancy
Slide 20
Slide 20 text
Web Consultancy
Collections of recipes, templates and other
configuration attributes to get stuff done.
Chunks of Ruby code that describe what stuff we
need to do to get that stuff done.
Cookbooks
Recipes
Slide 21
Slide 21 text
Web Consultancy
A virtual machine, cloud server or dedicate
server
Resource
Creates a user, expands a template, installs a
package, starts a service etc
Node
Slide 22
Slide 22 text
Web Consultancy
Port number, database name, file location etc
Template
A template which you create a file from inserting
variables
Attribute
Slide 23
Slide 23 text
Web Consultancy
package "ntp" do
action :install
end
!
template "/etc/ntp.conf" do
source "ntp.conf.erb"
owner "root"
group "root"
mode 0644
notifies :restart, resources(:service => "ntp")
end
!
service "ntp" do
action :start
end
Install package
Create config file
from template
Define service and
start NTP
Restart service
when config file
changes
Slide 24
Slide 24 text
Web Consultancy
Let’s make a cookbook to
install our PHP application
Slide 25
Slide 25 text
Web Consultancy
Slide 26
Slide 26 text
Web Consultancy
Our template
ServerName <%= @params[:server_name] %>
DocumentRoot <%= @params[:docroot] %>
!
>
Options FollowSymLinks
AllowOverride FileInfo Options
AllowOverride All
Order allow,deny
Allow from all
!
Options FollowSymLinks
AllowOverride None
!
Web Consultancy
web_app node['phpapp']['host'] do
template "phpapp.conf.erb"
docroot node['phpapp']['dir']
server_name node['phpapp']['host']
end
Our recipe
Auto-scaling
Web Consultancy
• We want to auto-scale quickly
• Our previous Chef and knife example takes
10 minutes to bootstrap our server
Slide 32
Slide 32 text
Auto-scaling
Web Consultancy
https://github.com/hellofuture-cookbooks/hf-lamp
hf-lamp
• Different recipes for installing
dependencies and setting up you
application configuration
Auto-scaling
Web Consultancy
• chef-solo to create an instance with
dependencies installed
• Create an AMI image from that instance
• Use that instance in you auto-scaling
launch configuration
Slide 36
Slide 36 text
Web Consultancy
Slide 37
Slide 37 text
Web Consultancy
Slide 38
Slide 38 text
Web Consultancy
Slide 39
Slide 39 text
Web Consultancy
Slide 40
Slide 40 text
Web Consultancy
Slide 41
Slide 41 text
Web Consultancy
Slide 42
Slide 42 text
Web Consultancy
Slide 43
Slide 43 text
Web Consultancy
Slide 44
Slide 44 text
Web Consultancy
Slide 45
Slide 45 text
When to auto-scale
Web Consultancy
!
• Create CloudWatch alarms on key metrics
such as CPU load
• Scale up when a high percentage of total of
the metric is being used
• Scale down when low percentage of the
metric is being used
Slide 46
Slide 46 text
When to auto-scale
Web Consultancy
!
• Test things out with CloudWatch alarms to
begin with
• Scale up quickly and scale down slowly
Slide 47
Slide 47 text
Amazon OpsWorks
Web Consultancy
!
• Chef based
• Lots of scaling configuration options
including scaling up on a schedule