Upload
somkiat-puisungnoen
View
1.192
Download
0
Embed Size (px)
DESCRIPTION
Geeky Academy Week 3 :: Vagrant + Puppet - Vagrant 101 - Vagrant 201 - Vagrant 301
Citation preview
VAGRANT
3rd WEEKSATURDAY, JULY 06, 2013 – SUNDAY, JULY 07, 2013
GEEK ACADEMY 2013
INSTRUCTOR TEAMTAVEE SOMKIAT THAWATCHAI
Tavee (Vee) Khunbida Somkiat (Pui) Puisungnuen Thawatchai (Boy) JongsuwanpaisanSiam Chamnan Kit
Siam Chamnan Kit
Siam Chamnan Kit
What Vagrant ?
ohttp://www.vagrantup.com/oBased on VirtualBox and RubyoManage VM with Simple Command lineoRun on
oWindowsoLinuxoMac OS
VAGRANT 101
GEEK ACADEMY 2013
Simple Command Line
$ gem install vagrant$ vagrant box add base <box url>$ vagrant init$ vagrant up
Step 1 :: Installation with Ruby Gem
$ gem install vagrant
Step 2 :: Add Base Box
$ vagrant box add base http://files.vagrantup.com/precise32.box
…….[vagrant] Downloading with Vagrant::Downloaders::File...[vagrant] Copying box to temporary location...[vagrant] Extracting box...[vagrant] Verifying box...[vagrant] Cleaning up downloaded box...
Step 3 :: Configuration
$ vagrant init
…..A `Vagrantfile` has been placed in this directory. You
are nowready to `vagrant up` your first virtual environment!
Please readthe comments in the Vagrantfile as well as
documentation on`vagrantup.com` for more information on using Vagrant.
Vagrantfile
Vagrant::Config.run do |config|
config.vm.box = "base“
end
Step 4 :: Boot
$ vagrant up
….[default] Importing base box 'base'...[default] Matching MAC address for NAT networking...[default] Clearing any previously set forwarded ports...[default] Fixed port collision for 22 => 2222. Now on port 2200.[default] Forwarding ports...[default] -- 22 => 2200 (adapter 1)[default] Creating shared folders metadata...[default] Clearing any previously set network interfaces...[default] Booting VM...[default] Waiting for VM to boot. This can take a few minutes.
Ready to SSH
User=vagrantPassword=vagrant
Optional Command
$ vagrant status$ vagrant halt$ vagrant destroy$ vagrant reload$ vagrant provision$ vagrant suspend$ vagrant resume
Summary for 101
oReduce setup timeoSimpleoSelf-serviceoConsistencyoRepeat
VAGRANT 201
GEEK ACADEMY 2013
https://github.com/up1/geeky_devops
Working with Vagrantfile
oSpecified base boxoNetwork ConfigurationoSharing FolderoMultiple VM
Specified Base Box
Vagrant::Config.run do |config| config.vm.box = "lucid32“
config.vm.box_url = "http://files.vagrantup.com/lucid32.box"
config.vm.box_url = "c:\\demo-geeky\\lucid32.box"
end
Network Configuration
Vagrant::Config.run do |config| config.vm.network :hostonly,
"33.33.33.10"
end
Sharing Folder
Vagrant::Config.run do |config| config.vm.share_folder "foo", "/guest/path",
"/host/path"
end
Path on VM Path on Local
Sharing Folder
Vagrant::Config.run do |config|
config.vm.share_folder "work", "/var/www", "./webapp”
end
Multiple VM in Stack
oWeb ServeroApplication ServeroDatabase ServeroCaching ServeroMessaging Server
Web Server and DB ServerVagrant::Config.run do |config|
config.vm.define :web do |web_config| web_config.vm.host_name = "web01.internal" web_config.vm.network :hostonly,
"192.168.0.100" end
config.vm.define :db do |db_config| db_config.vm.host_name = "db01.internal" db_config.vm.network :hostonly, "192.168.0.101" end
end
DEMO MORE
oFlexible configurationo# of ServeroHostnameoManage IP
DEMO MOREoWeb Server
oweb-01.vagrant.internal 33.33.33.11 oweb-02.vagrant.internal 33.33.33.12
oDB Serverodb-01.vagrant.internal 33.33.33.21
Serversnodes = { 'web' => [2, 10], 'db' => [1, 20],}
Create Serversnodes.each do |prefix, (count, ip_start)| count.times do |i|
hostname = "%s-%02d" % [prefix, (i+1)]
config.vm.define "#{hostname}" do |box|
box.vm.host_name = "#{hostname}.vagrant.internal"
box.vm.network :hostonly, "33.33.33.#{ip_start+i}“
end
endend
VAGRANT 301
GEEK ACADEMY 2013
Vagrant with Puppet
ohttps://puppetlabs.comoConfiguration management with CodeoRubyoRepeatable
Demo :: Install all in one
oManage package with Puppeto Javao Apache Tomcato Rediso RabbitMQ
https://github.com/up1/geeky_devopsdemo-puppet
Structure of Puppet
opuppetomanifests/default.ppomodules
o javaomanifests/init.pp
otomcatomanifests/init.pp
oredisomanifests/init.pp
orabbitMQomanifests/init.pp
Starting point
Vagrantfile
config.vm.provision :puppet do |puppet|
puppet.manifests_path = "puppet/manifests"
puppet.manifest_file = "default.pp"puppet.module_path = "puppet/modules"
end
Vagrant provision
Starting point
Default.pp
include bootstrap include redisinclude javainclude tomcatinclude rabbitmq
Step to execute modules
Structure of Puppet
opuppetomanifests/default.ppomodules
o javaomanifests/init.pp
otomcatomanifests/init.pp
oredisomanifests/init.pp
orabbitMQomanifests/init.pp
Starting point each module
Init.pp :: Java
class java {package { "openjdk-7-jdk":
ensure => installed,require => Exec['apt-get update']
}}
Init.pp :: Package Apache Tomcat
class tomcat { package { "tomcat6": ensure => installed, require => Package['openjdk-7-jdk'], } package { "tomcat6-admin": ensure => installed, require => Package['tomcat6'], }
}
Init.pp :: Service Apache Tomcat
class tomcat {
service { "tomcat6": ensure => running, require => Package['tomcat6'], subscribe => File["tomcat-users.xml"] }
}
Init.pp :: Tomcat-users.xml
class tomcat {
file { "tomcat-users.xml": owner => 'root', path => '/etc/tomcat6/tomcat-users.xml', require => Package['tomcat6'], notify => Service['tomcat6'], content => template( '/path/tomcat/templates/tomcat-
users.xml.erb') }
}
Tomcat-users.xml.erb
<?xml version='1.0' encoding='utf-8'?><tomcat-users>
<role rolename="manager"/><role rolename="admin"/><user name="tomcat-admin" password="12345" roles="manager,admin"/>
</tomcat-users>
More Demo
ohttps://github.com/up1/geeky_devopsodemo-multi-puppet
box.vm.provision :puppet do |puppet| puppet.manifests_path = "puppet/manifests" puppet.manifest_file = "#{prefix}.pp" puppet.module_path = "puppet/modules" end
Question ?
GEEK ACADEMY 2013
THANK YOU FORYOUR TIME
GEEK ACADEMY 2013