Develop and deploy using Hybrid Cloud Strategies confoo2012

Preview:

DESCRIPTION

Slides for my Hybrid Cloud talk at Confoo

Citation preview

Thijs  FerynEvangelist+32  (0)9  218  79  06thijs@combellgroup.com

Develop  &  deploy  using  hybrid  cloud  strategies

Very  excited  to  be  here  !

THIJS

TAZE

Evangelist

@ThijsFeryn

Please  rate  my  talk  on  

Joind.in

https://joind.in/4951

What  is  Cloud?

“That’s  where  rain  comes  from”

Andrei  Zmievski

Cloud=

Internet

DefiniXon

A  model  for  consumpXon  &  delivery  on  the  internet  where  flexibility  is  essenXal  &  can  be  

guaranteed  through  abstracXon

Internet  as  a  uXlity

Translated  to  what  we  know  &  need

Always  available

Fast  (enough)

Scalability

Up  &  down  vs  out  &  in

Focus  on  using,  do  what  you’re  good  at

Leave  the  rest  to  others

Higher  up  the  stack

Economic  advantages

Less  moneyLess  effortLess  risk

Less  worries

Hybrid  let’s  you  do  that

Hybrid  is  just  a  fancy  way  of  saying

Pick  the  pieces  of  the  puzzle  yourself

Amazon  web  services

✓CompuXng–EC2–ELB–Auto  scaling

✓Storage–S3–EBS

✓Database–RDS–DynamoDB–SimpleDB–ElasXcache–SQS✓CDN–CloudFront

Self-­‐service  Iaas

Windows  Azure

✓CompuXng✓Storage–Blob  storage–Table  storage✓CDN✓SQL  Azure✓Data  sync✓Service  Bus

Self-­‐service  Paas

Orchestra

✓CompuXng✓Database

–Memcached–MySQL  &  RDS–CouchDB–MongoDB–Redis

PHP  Paas  on  top  of  AWS

Combell

Fully  customized  &  managed  soluXons

Easy  peasy,  right?

Single  point  of  failure

Shared  nothing

Nothing  is  local

Distributed  systems

Easy  to  deploy  &  manage?

How  do  you  deal  with

$_SESSIONS?

ReplicaXonR/W  splimng

“Cloud  is  for  green  field  projects”

Maarten  Balliauw

Let’s  do  it  !

Infrastructure

✓Basics–Webservers–MySQL  servers–File  servers✓AddiXonal  servers–Caching  servers–Reverse  proxy  servers✓External  CDN

Single  server  setup

Single  server  setup

✓Developer–Everything  is  local•Files•Databases

✓Sysadmin–Sits  back,  drinks  some  coffee

Single  server  setup

✓Amazon–1  EC2  instance–Local  MySQL  or  RDS  (as  a  service)–Local  files✓Azure–Single  App  deployment–Include  PHP  &  MySQL  in  package  script✓Orchestra–Single  App  deployment–Request  MySQL  database  or  RDS

What  about  the  Cloud?

Separate  MySQL

Separate  MySQL

✓Developer–Change  connecXonstring(s)✓Sysadmin–Sets  up  separate  server–Tunes  for  MySQL

Separate  MySQL

✓Amazon–Extra  EC2  instance  for  MySQL–RDS✓Azure–MySQL  deployment  with  worker  role–Doesn’t  scale  well–Use  SQL  Azure  instead✓Orchestra–By  default  separate–Create  separate  MySQL  database–RDS

What  about  the  Cloud?

MulXple  MySQL’s

MulXple  MySQL’s

✓Developer–Read  write  splimng  in  code–Connect  to  loadbalanced  hostname

✓Sysadmin–Setup  servers–Configure  replicaXon•Master/master•Master/slave

–Add  to  loadbalancing

MulXple  MySQL’s

Use  mysqlnd_ms  for  R/W  splimng  in  case  of  crappy  code{        "myapp":  {                "master":  {                        "write_group":  {                                "host":  "master.db.myapp.ext",                                "port":  "3306"                        }                },                "slave":  {                        "read_group":  {                                "host":  "slave.db.myapp.ext",                                "port":  "3306"                        }                }        }}

mysqlnd_ms_plugin.ini

mysqlnd_ms.enable=1mysqlnd_ms.ini_file=/path/to/mysqlnd_ms_plugin.ini

php.ini

<?php$mysqli = new mysqli("myapp", "username", "password", "database");$pdo = new PDO('mysql:host=myapp;dbname=database', 'username', 'password');$mysql = mysql_connect("myapp", "username", "password");

ConnecXon  string

MulXple  MySQL’s

✓Amazon–MulXple  EC2  instances  with  replicaXon  and  loadbalancing–RDS  with  read  replica

✓Azure–Include  PHP  &  MySQL  in  package  script–Doesn’t  scale–Use  SQL  Azure

✓Orchestra–RDS–Xeround

What  about  the  Cloud?

MulXple  web  

servers

MulXple  web  servers

✓Developer–MulXple  places  to  deploy–Where  are  my  staXc  assets?–Sessions?

✓Sysadmin–MulXple  servers  behind  loadbalancer–$_SESSION  clustering  via  Memcached  or  sXcky  sessions–Shared  storage

Memcached  session  handler

session.save_handler  =  memcachedsession.save_path=  “mc1.myapp.ext:11211,mc2.myapp.ext:11211”

php.ini

MulXple  Web  servers

✓Amazon–MulXple  EC2  instances  –Use  ELB  for  loadbalancing–AMI  for  easy  setup–Config  management  (puppet,  chef,  ...)

✓Azure–Out  of  the  box–Tuning  possible

✓Orchestra–Out  of  the  box

What  about  the  Cloud?

Offload  staXc  files

Offload  staXc  files

✓Developer–Sync  current  assets–Store  new  files  on  external  servers–Use  external  hostname  when  referencing  files

✓Sysadmin–Tune  external  servers  for  staXc  content–CDN,  perhaps?

Offload  staXc  files

✓Amazon–EC2  instances  for  storage  with  clustered  file  system–S3  buckets

✓Azure–Blob  storage

What  about  the  Cloud?

When  the  

pressure  is  on

Auto  scaling  &  load  balancing

CDN  &  asset  offloading

Reverse  (caching)  proxy

Memcached

Adaptyourcode

Storage

require_once  'Zend/Service/WindowsAzure/Storage/Blob.php';  $storageClient  =  new  Zend_Service_WindowsAzure_Storage_Blob();$result  =  $storageClient-­‐>putBlob('testcontainer',  'example.txt',  '/example.txt');  echo  'Blob  name  is:  '  .  $result-­‐>Name;

require_once  'Zend/Service/Amazon/S3.php';  $s3  =  new  Zend_Service_Amazon_S3($my_aws_key,  $my_aws_secret_key);  $s3-­‐>createBucket("my-­‐own-­‐bucket");  $s3-­‐>putObject("my-­‐own-­‐bucket/myobject",  "somedata");echo  $s3-­‐>getObject("my-­‐own-­‐bucket/myobject");

Azure  Blog  storage

Amazon  S3

<?php$storage = Zend_Cloud_StorageService_Factory::getAdapter(array(    Zend_Cloud_StorageService_Factory::STORAGE_ADAPTER_KEY => 'Zend_Cloud_StorageService_Adapter_S3',    Zend_Cloud_StorageService_Adapter_S3::AWS_ACCESS_KEY   => $amazonKey,    Zend_Cloud_StorageService_Adapter_S3::AWS_SECRET_KEY   => $amazonSecret,));$data = file_get_contents('/my/local/dir/picture.jpg');$returnedData = $storage->storeItem('/my/remote/path/picture.jpg', $data);

Supports  Azure  &  AWS

<?php$storage = Zend_Cloud_StorageService_Factory::getAdapter(array(    Zend_Cloud_StorageService_Factory::STORAGE_ADAPTER_KEY => 'Zend_Cloud_StorageService_Adapter_FileSystem',    Zend_Cloud_StorageService_Adapter_FileSystem::LOCAL_DIRECTORY   => $localDirectory,));$data = file_get_contents('/my/local/dir/picture.jpg');$returnedData = $storage->storeItem('/my/remote/path/picture.jpg', $data);

Even  supports  local  file  system

Put  opXons  in  config  file

Design  pawernse.g.

Dependency  injecXon

Modular  designAbstracXon  

layers

+  W3  Total  Cache

W3  Total  Cache

✓Page  caching  -­‐Memcached  (loadbalanced)-­‐ Varnish  (loadbalanced)

✓Database  &  object  cache-­‐Memcached  (loadbalanced)

✓CDN-­‐ Push  to  S3  or  Azure  Blob  storage  buckets-­‐ Pull  from  CDN  (CloudFront  or  Azure)-­‐ Custom  hostnames

✓Scale  across  EC2  nodes  with  ELB

Deploy  your  code

Deploy  your  code

✓General  deployment  methods–Capistrano–Phing–Puppet  (config  is  code  too)–Version  control  tools

✓Amazon  specific–AMI’s

✓Azure  specific–Scaffolding  &  packaging    command  line  tool–Upload  packages  in  control  panel

✓Orchestra  specific–Git

About  Azure  deployment

About  Azure  deployment

scaffolder  run  -­‐out="c:\temp\HelloAzure\Project"

package  create  -­‐in="C:\temp\HelloAzure\Project"  -­‐out="C:\temp\HelloAzure\DeployDev"  -­‐dev=true

package  create  -­‐in="C:\temp\HelloAzure\Project"  -­‐out="C:\temp\HelloAzure\DeployProduction"  -­‐dev=false

package  and  run  on  emulator

package  for  deployment

About  Azure  deployment

Certificate=XXXXXXXXSubscriptionId=XXXXXPassphrase=XXXXXXXXXStorageAccount=XXXXXPackageLocation=_files\PhpOnAzure.cspkgServiceConfigLocation=_files\ServiceConfiguration.cscfg

Semngs.ini

About  Azure  deployment

deployment.php  CreateFromLocal  -­‐-­‐ConfigFile="settings.ini"  -­‐-­‐Name="mysubdomain"  -­‐-­‐DeploymentName="testdeploy"  -­‐-­‐Label="testdeploy"  -­‐-­‐BySlot="staging"  -­‐-­‐StartImmediately  -­‐-­‐WaitFor

Deploy  to  staging

About  Azure  deployment

deployment.php  Swap  -­‐-­‐ConfigFile="settings.ini"  -­‐-­‐Name="mysubdomain"  -­‐-­‐WaitFor

deployment.php  EditInstanceNumber  -­‐-­‐ConfigFile="settings.ini"  -­‐-­‐Name="subdomain"  -­‐-­‐ByName="testdeploy"  -­‐-­‐RoleName="PhpOnAzure.Web"  -­‐-­‐NewInstanceNumber=2

Swap  to  producXon

Scale  out

Mix  &  match

Management  models  (oAen  forgoBen)

Management  models  (oAen  forgoBen)

Managed  Cloud  is  the  new  dedicated  server

Unmanaged  Cloud  is  virtual  colocaXon

Management  models  (oAen  forgoBen)

Custom  soluXon  at  hoster  under  heavy  SLA

Burst  model  at  unmanaged  vendor

When  to  choose  what?

Recommended