• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
Virtualized development environments   phpne - may 2012
 

Virtualized development environments phpne - may 2012

on

  • 16,165 views

A talk at PHP North East, 12th May 2012 - introduction to Virtualization, Vagrant, Configuration Management / Infrastructure as Code, Puppet and Chef...

A talk at PHP North East, 12th May 2012 - introduction to Virtualization, Vagrant, Configuration Management / Infrastructure as Code, Puppet and Chef...

Statistics

Views

Total Views
16,165
Views on SlideShare
2,627
Embed Views
13,538

Actions

Likes
10
Downloads
68
Comments
0

23 Embeds 13,538

http://www.planetdevops.net 5392
http://www.ichilton.co.uk 4126
http://phpne.org.uk 3704
http://infra-talk.org 113
http://feeds.feedburner.com 60
http://abtasty.com 39
http://translate.googleusercontent.com 27
http://www.betterbrandagency.com 26
http://webcache.googleusercontent.com 11
http://growthfunders.dev.betterbrandagency.com 9
http://lanyrd.com 7
http://www.newsblur.com 6
http://ranksit.com 5
http://127.0.0.1 3
http://prlog.ru 2
https://twimg0-a.akamaihd.net 1
https://www.google.co.uk 1
http://www.365dailyjournal.com 1
http://www.inoreader.com 1
https://www.google.com 1
http://localhost 1
http://rss.akamaras.com 1
http://www.ranksit.com 1
More...

Accessibility

Categories

Upload Details

Uploaded via as Apple Keynote

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n

Virtualized development environments   phpne - may 2012 Virtualized development environments phpne - may 2012 Presentation Transcript

  • Virtualized DevelopmentEnvironments with Vagrant Ian Chilton PHP North East - 14th May 2012
  • IntroductionIan ChiltonBetter Brand Agencyhttp://www.betterbrandagency.comhttp://www.bettercommunities.co.ukTwitter: @ichiltonWeb: http://www.ichilton.co.ukLinkedIn: http://uk.linkedin.com/in/ichilton
  • Contents- Introduction to: - Development Environments - Virtualization- Why Virtualize your development environment?- Introduction to Vagrant- Using Vagrant- Vagrant Plugins- Automated Provisioning (Configuration Management)
  • Development Environments
  • Development EnvironmentsWe don’t want to be working on live sites.
  • Development EnvironmentsWe don’t want to be working on live sites.So we setup a development environment.
  • Development EnvironmentsWe don’t want to be working on live sites.So we setup a development environment.DEV StagingVCS LIVE
  • Development EnvironmentsWe don’t want to be working on live sites.So we setup a development environment. DEVDEV Staging Staging VCS DEVVCS LIVE LIVE DEV
  • Development Environments We don’t want to be working on live sites. So we setup a development environment. DEV DEV Staging Staging VCS DEV VCS LIVE LIVE DEVWe work on development, push/pullto/from version control and deploy tostaging and live.
  • Development Environments We don’t want to be working on live sites. So we setup a development environment. DEV DEV Staging Staging VCS DEV VCS LIVE LIVE DEVWe work on development, push/pullto/from version control and deploy tostaging and live. It’s DEV we’re going to be talking about here.
  • Development Environments
  • Development EnvironmentsNumber of (valid) ways:
  • Development EnvironmentsNumber of (valid) ways: - Copy of site (on live server) - Can easily affect the live site.
  • Development EnvironmentsNumber of (valid) ways: - Copy of site (on live server) - Can easily affect the live site. - Shared development server - Local / Remote / Dedicated / Cloud / VPS - Cost - Remote = latency / connection failure - Setup / management / maintenance - All developers and all projects sharing same hardware, software, versions etc.
  • Development Environments
  • Development EnvironmentsNumber of (valid) ways: - continued
  • Development EnvironmentsNumber of (valid) ways: - continued - Develop Locally: - MAMP (mac) or WAMP (windows) - Homebrew (mac), apt-get etc (linux) to install services locally
  • Development EnvironmentsNumber of (valid) ways: - continued - Develop Locally: - MAMP (mac) or WAMP (windows) - Homebrew (mac), apt-get etc (linux) to install services locally - Self sufficient - no remote latency / connection failure - However... - Clutter on workstation - Still shared between projects, set versions etc... - Different OS / platform / architecture
  • Development Environments
  • Development EnvironmentsConsider these scenarios (just some examples of many...)
  • Development EnvironmentsConsider these scenarios (just some examples of many...)The methods on the previous slides could install a different (mucholder or newer) version of a service like MySQL or PHP than theproduction box.You could then inadvertently code with something only added in alater version, or use something which had bugs in earlierversions.You’d there for have code which works in development but notwhen deployed to production.
  • Development Environments
  • Development EnvironmentsConsider these scenarios (just some examples of many...)
  • Development EnvironmentsConsider these scenarios (just some examples of many...)Both Windows and OS X use case insensitive filesystems.Imagine writing some code which used MyFile.txt.You could call this file myfile.txt and it would work on Windows/Mac.On Linux that would either error or be a completely different file.
  • Virtualization
  • VirtualizationSuch bugs can be very difficult and time consuming to track down.
  • VirtualizationSuch bugs can be very difficult and time consuming to track down.The lesson...We really need to develop on the same operatingsystem, architecture, package versions andconfiguration as production.
  • Virtualization
  • VirtualizationVirtualization is a technology where by a number of “virtualmachines” can be hosted on top of a single machine.
  • VirtualizationVirtualization is a technology where by a number of “virtualmachines” can be hosted on top of a single machine.The software running on the virtual machines (guests) is separatedfrom the software running on the “host”.
  • VirtualizationVirtualization is a technology where by a number of “virtualmachines” can be hosted on top of a single machine.The software running on the virtual machines (guests) is separatedfrom the software running on the “host”.The software used to make this possible is called a “hypervisor”.
  • VirtualizationVirtualization is a technology where by a number of “virtualmachines” can be hosted on top of a single machine.The software running on the virtual machines (guests) is separatedfrom the software running on the “host”.The software used to make this possible is called a “hypervisor”.This allows us to run different software on different virtual machines -for example you could run Windows and Linux virtual machines on aMac.
  • Types of VirtualizationFull VirtualizationAlmost complete simulation of the actual hardware.This allows the guest operating systems to run unmodified.Eg: - Oracle Virtualbox - Free virtualization product for the desktop - Cross platform - Windows, OS X, Linux - Lots of features - VMWare - Commercial (££) - Workstation and Server products
  • Types of VirtualizationParavirtualizationThe hardware environment is not simulated.The guest operating system is specially modified to allow thehypervisor to run the guests in their own isolated domain.Eg: - Xen which is used by: - Amazon EC2 - Rackspace Cloud - Some VPS providers
  • Types of VirtualizationHardware Assisted VirtualizationModern Intel or AMD CPU’s contain native virtualization functionalityon the CPU - Intel VT-x and AMD-V.Eg: - Linux KVM (Kernel Virtual Machine) which is used by: - Bytemark - Brightbox - VPS providers - Xen, Virtualbox & VMWare also support this as well, for hosts thathave the hardware support.
  • Types of VirtualizationOperating System Level Virtualization (aka. containers)The virtualization is implemented in software, on the host operatingsystem/kernel.The guest operating systems share the kernel of the host, but runthe guest operating system independently of the host.This allows isolated virtual machines and different distributions, butis generally limited to Unix based operating systems.Eg: - OpenVZ - LXC on Linux - FreeBSD jailsOften used by budget VPS providers as they can over-sell.
  • Advantages of Using Virtualization
  • Advantages of Using Virtualization- We can run the exact same operating system and setup as theproduction boxes, on top of any other machine, be it Mac, Windowsor Linux.- We can install the same software / packages / versions.- Everything is run in a contained sandbox and resources can bemanaged.- We can create distributable images to share.- If we run the VM’s locally, we can develop offline.
  • Disadvantages of Using Virtualization
  • Disadvantages of Using Virtualization- Many of the products we’ve mentioned require Linux (or anotherUNIX operating system) and don’t run on Mac or Windows.- Require searching around for operating system images or installingthe operating system on the VM manually.- Can be complicated/time consuming to learn, setup and configure.
  • Disadvantages of Using Virtualization- Many of the products we’ve mentioned require Linux (or anotherUNIX operating system) and don’t run on Mac or Windows.- Require searching around for operating system images or installingthe operating system on the VM manually.- Can be complicated/time consuming to learn, setup and configure.What we need is a simple and quick way ofbringing up virtual machines with minimal fuss.
  • VagrantCreated by Mitchell Hashimoto and John BenderCommand line interface/wrapper around Oracle’s free VirtualBoxsoftware (support for other hypervisors are in the works).Allows virtual machines to be created, inside of a minute, from pre-provided images, with a few simple commands. http://vagrantup.com
  • VagrantWe can use vagrant machines for:- Development- Testing- Experimenting new/different software/settings- Testing configuration management systems (explained later). http://vagrantup.com
  • Apprehensions
  • Apprehensions- Won’t it be slow? - Headless Linux VM’s aren’t as resource hungry as a Windowsvirtualized.- I want to use my local graphical editor... - Vagrant automatically creates a shared directory on the host.
  • Install Vagrant
  • Install Vagrant- Install Oracle Virtualbox (free from: http://virtualbox.org) - versionsfor Windows, Mac OS X or Linux. • Plus the extension pack.- Install Vagrant (free from: http://downloads.vagrantup.com)Still available as a Ruby gem but as of the recent v1.0, installers areprovided for Windows, Mac and Linux (deb and rpm).$ vagrant -vVagrant version 1.0.3
  • Base Boxes
  • Base BoxesPre-packaged operating system images.Official base boxes - Ubuntu LTS (long term support) releases.Ubuntu 10.04 (Lucid Lynx)$ vagrant box add lucid32 http://files.vagrantup.com/lucid32.box$ vagrant box add lucid64 http://files.vagrantup.com/lucid64.boxUbuntu 12.04 (Precise Pangolin):$ vagrant box add precise32 http://files.vagrantup.com/precise32.box$ vagrant box add precise64 http://files.vagrantup.com/precise64.box
  • Basic Vagrant Usage
  • Basic Vagrant Usage$ mkdir vagrant$ cd vagrant$ mkdir mydev$ cd mydevCreate a new config file (VagrantFile) for this instance:$ vagrant init lucid32Boot the machine (create from base box the 1st time):$ vagrant upSSH in:$ vagrant ssh
  • Basic Vagrant Usage
  • Basic Vagrant UsageVagrant automatically maps /vagrant inside the VM to the directoryon the host:vagrant@vagrant:~$ ls /vagrantindex.html VagrantfileCtrl-d exits the SSH session and takes us back to the host.Suspend the machine:$ vagrant suspend$ vagrant resumeShut down the machine:$ vagrant haltDestroy the machine:$ vagrant destroy
  • Vagrant Configuration
  • Vagrant ConfigurationThe “vagrant init” created a VagrantFile for this VM.Vagrant::Config.run do |config| config.vm.box = "lucid32"endWe can edit this to add additional options.
  • Vagrant Configuration
  • Vagrant ConfigurationGUI or Headless?:Vagrant::Config.run do |config| config.vm.box = "lucid32" # Boot with a GUI so you can see the screen. # (Default is headless) # config.vm.boot_mode = :guiend
  • Vagrant Configuration
  • Vagrant ConfigurationPort Forwarding:Vagrant::Config.run do |config| config.vm.box = "lucid32" # Map port 8080 on the host to port 80 in the VM: config.vm.forward_port 80, 8080end
  • Vagrant Configuration
  • Vagrant ConfigurationControl VirtualBox:Vagrant::Config.run do |config| config.vm.box = "lucid32" # Make the VM have 1GB RAM: config.vm.customize ["modifyvm", :id, "--memory", 1024]end
  • Vagrant Configuration
  • Vagrant ConfigurationMultiple Machines:Vagrant::Config.run do |config| # Web Server: config.vm.define :web do |web_config| web_config.vm.box = "web" web_config.vm.forward_port 80, 8080 end # Database Server: config.vm.define :db do |db_config| db_config.vm.box = "db" db_config.vm.forward_port 3306, 3306 endend
  • Vagrant Configuration
  • Vagrant ConfigurationNetworking:- Host Only - local communication between different VM’s. Vagrant::Config.run do |config| config.vm.box = "lucid32" config.vm.network :hostonly, “192.168.50.1” end- Bridged - bridge the VM onto the host’s network so we can access anythingon the network, and they can access the VM as if it was a normal machine onthe network. Vagrant::Config.run do |config| config.vm.box = "lucid32" config.vm.network :bridged end
  • Vagrant Configuration
  • Vagrant ConfigurationPackaging:Use as a starting point, or distribute instances.$ vagrant package --vagrantfile Vagrantfile.pkgThe --vagrantfile Vagrantfile.pkg option tells Vagrant to take the options placedin Vagrantfile.pkg and add them into the box so things like port forwarding willbe done automatically.We can then use this as normal:$ vagrant box add my_box /path/to/the/package.box$ vagrant init my_box$ vagrant up
  • Vagrant Plugins
  • Vagrant PluginsVagrant Box.es - Gareth Rushgrove has created a site at: http://vagrantbox.eswhich is a list of links to base boxes that people have built and made public(currently 49 boxes).He has also created a vagrant plugin to search, view and install them:https://github.com/garethr/ruby-vagrantboxesSahara - allow vagrant to run in a sandbox so any changes can be rolled back:https://github.com/jedi4ever/saharaVagrant Snap - allow snapshots and supports a multi vm environment:https://github.com/t9md/vagrant-snapVagrant Hosts - automatically update a dns server with vagrant hostnames:https://github.com/BerlinVagrant/vagrant-dnsVagrant plugin for Jenkins:http://unethicalblogger.com/2012/03/13/introducing-the-vagrant-plugin.html
  • Vagrant Plugins
  • Vagrant PluginsVeeWee - https://github.com/jedi4ever/veeweeBuild custom base boxes from scratch.Includes templates for popular distributions - CentOS, Debian, Fedora,ArchLinux, Gentoo, openSUSE, Ubuntu and even FreeBSD.
  • Vagrant Plugins
  • Vagrant PluginsVeeWee - https://github.com/jedi4ever/veewee$ veewee vbox define myubuntubox ubuntu-12.04-server-i386The basebox myubuntubox has been succesfully created fromthe template ubuntu-12.04-server-i386You can now edit the definition files stored in definitions/myubuntubox or build the box with:veewee vbox build myubuntubox$ ls definitions/myubuntuboxdefinition.rb postinstall.sh preseed.cfg
  • Vagrant Plugins
  • Vagrant PluginsVeeWee - https://github.com/jedi4ever/veeweeHere, we can customise the build.- definition.rb - contains the parameters for the box: cpu’s, memory, disk, O/S, ISO fileand url, boot sequence, SSH details etc.- preseed.cfg - This is the file the Debian/Ubuntu installer uses to automate theinstallation.- postinstall.sh - This is a shell script which is ran on the VM after the installation. In thiscase, it will: •Upgrade the O/S (apt-get update && apt-get dist-upgrade) •Install the dependancies for Ruby. •Install (or build from source) Ruby. •Install Puppet and Chef •Create a vagrant user and add in the standard Vagrant SSH public key into ~/.ssh/ authorized_keys.
  • Vagrant Plugins
  • Vagrant PluginsVeeWee - https://github.com/jedi4ever/veeweeWe now build the box:$ veewee vbox build myubuntubox- Download’s ISO the first time.- Starts a mini web server to serve the preseed.cfg file.- Creates a VirtualBox VM and boots the ISO.- At the boot prompt, it enters a custom boot prompt which points it to the urlfor the preseed.cfg.- The install complete’s automatically (using the preseed.cfg file) and veeweejust waits until it can successfully SSH to the VM.
  • Vagrant Plugins
  • Vagrant PluginsVeeWee - https://github.com/jedi4ever/veeweeOnce the build is complete (takes some time), we can run some automatedCucumber tests against the box:$ veewee vbox validate myubuntubox...7 scenarios (7 passed)21 steps (21 passed)0m14.810sThis checks the box is working and that Ruby, Ruby Gems, Chef, Puppet etcis responding as intended.If so, we can then build the box and add it into Vagrant:$ vagrant basebox export myubuntubox
  • Automated Provisioning (Configuration Management)
  • Automated Provisioning (Configuration Management)We’ve now got the ability to quickly spin up virtual machines as we requirethem.However, that only gets us a clean install - we’ve still got to start installingpackages and configuring things how we like them.If we are looking to share environments with colleagues etc, the problem withpre-packaged boxes/images is that they get out of date so they either have tobe periodically updated or extra steps added in whenever they are used.
  • Automated Provisioning (Configuration Management)
  • Automated Provisioning (Configuration Management)This also doesn’t just apply to development - what if we have tens or hundreds ofproduction servers?- How can we ensure that every time we setup a new server, all of the correct setup stepsare followed?- How can we ensure that the development, staging and production servers are all setupthe same.- What if we have a failure and it takes someone hours of running manual commands tobuild a new server? - what if a whole platform of tens or hundreds of servers fail?(connectivity or business)- How boring is it going to get for someone manually setting up servers?- We could document it, but will it be kept up-to-date?- What about maintaining the boxes on an ongoing basis? - how do we keep them up todate? when someone new starts, how long will it take to go round a lot of servers and addtheir user and ssh key or to apply a firewall change to all servers?
  • Automated Provisioning (Configuration Management)
  • Automated Provisioning (Configuration Management)This is where something called “Infrastructure as code” comes in.What if we were to do our server setup and management as we dodevelopment:- Write code (which also acts as documentation)- Put the code into version control so we can: - See and analyse changes, who made them and when. - Have branches and tags. - Easily roll back to old versions.- Run automated tests with Rspec and Cucumber to ensure everything isworking correctly without manually checking each server.- TDD - Test Driven DevelopmentThis ensures that server setup is consistent, reproducible, fast, mistake freeand automatable.
  • Automated Provisioning (Configuration Management)
  • Automated Provisioning (Configuration Management)In the past, people would write shell scripts to do this. However, this is difficultto manage and maintain.There are now a number of “configuration management” tools writtenspecifically for this purpose.The most popular and widely used of these is Puppet and Chef.
  • Automated Provisioning (Configuration Management)
  • Automated Provisioning (Configuration Management)Puppet: Puppet Labs - founded by Luke Kanies in 2005. Uses a declarative language to describe system configuration. Widely used and trusted by a number of large enterprise users - Wikimedia, Dell, Rackspace, Zynga, Twitter, New York Stock Exchange, Disney, Citrix, Oracle, Stanford University, Google and GovUK. James Turnbull (works for Puppet Labs) has written two books about Puppet which are published through Apress: - Pulling strings with Puppet - Pro Puppet -“Puppet 2.7 Cookbook” by John Arundel (Packtpub)
  • Automated Provisioning (Configuration Management)
  • Automated Provisioning (Configuration Management)Chef: Opscode (2009) Recipes written in pure Ruby. Opscode provides a “Hosted Chef” service to avoid running a local Chef server (like Github is to Git). Cookbooks - sharable! ! (although Puppet now has “Puppet Forge”) Knife - feature rich command line tool. Documentation improving: - Wiki - Stephen Nelson Smith, author of “Test Driven Infrastructure with Chef” is working on “Chef: The Definitive Guide” which is due to be published in September. - Podcast: http://www.foodfightshow.org/2012/03/episode-5-getting-started-with- chef.html
  • Automated Provisioning (Configuration Management)
  • Automated Provisioning (Configuration Management)Both products can run in both a standalone mode or a client-server model -Vagrant supports both of these.In the client/server model, the client will automatically “phone home” every sooften to check for changes.Idempotence:Run multiple times without affecting the result.i.e:- Instead of saying “Install Apache”, we say “Apache should be installed”.- Instead of “chown root.root myfile” we say “myfile should have this owner /group and these permissions.
  • Automated Provisioning (Configuration Management)
  • Automated Provisioning (Configuration Management)Simple Puppet Example:$ mkdir manifestsIn the VagrantFile:config.vm.provision :puppetORVagrant::Config.run do |config| config.vm.provision :puppet do |puppet| puppet.manifests_path = "manifests" puppet.manifest_file = "my_manifest.pp" endend
  • Automated Provisioning (Configuration Management)
  • Automated Provisioning (Configuration Management)Simple Puppet Example:In manifests/default.pp:class apache { package { "apache2": ensure => present, } service { "apache2": ensure => running, require => Package["apache2"], }}include apache
  • Automated Provisioning (Configuration Management)
  • Automated Provisioning (Configuration Management)Simple Puppet Example:file { "/etc/apache/apache.conf": owner => root, group => root, mode => 644, source => "puppet:////vagrant/puppet/files/apache.conf", require => Package["apache2"], notify => Service["apache2"] } file { "/etc/apache2/sites-available/vagrantsite": owner => root, group => root, mode => 644, source => "puppet:////vagrant/puppet/files/vhost.conf", require => Package["apache2"], notify => Service["apache2"] }
  • Automated Provisioning (Configuration Management)
  • Automated Provisioning (Configuration Management)Simple Puppet Example: file { "/etc/apache2/sites-enabled/vagrantsite": ensure => symlink, target => "/etc/apache2/sites-available/vagrantsite", require => Package["apache2"], notify => Service["apache2"] } file { "/etc/apache2/sites-enabled/default": ensure => absent, require => Package["apache2"], notify => Service["apache2"] }
  • More Information
  • More InformationVagrant:http://www.vagrantup.comGoogle Group: http://groups.google.com/group/vagrant-up#vagrant on irc.freenode.netPuppet:http://puppetlabs.com#puppet on irc.freenode.nethttp://www.puppetcookbook.comChef:http://www.opscode.com#chef on irc.feenode.netOther:http://devopsweekly.com