More Related Content Similar to A brief introduction to Vagrant – 原來 VirtualBox 可以這樣玩 Similar to A brief introduction to Vagrant – 原來 VirtualBox 可以這樣玩 (20) More from Wen-Tien Chang (20) A brief introduction to Vagrant – 原來 VirtualBox 可以這樣玩2. 我是誰?
• 張⽂文鈿 a.k.a. ihower
• http://ihower.tw
• http://twitter.com/ihower
• Ruby Developer since 2006
• CTO, Faria Systems Ltd.
• The organizer of RubyConf Taiwan
• http://rubyconf.tw
4. Agenda
• Why?
• What’s Vagrant
• Features
• Shared Folder
• Networking
• Provisioning
• Pachaging
• Multi-VM
• More Providers
• Conclusion
30. VM Providers
• Virtual Box
• Vmware Fusion
• Parallels
• LXC
• KVM
• Cloud computing:
• AWS EC2
• Rackspace Cloud
35. 使⽤用 VM 的好處
• Isolated
• Repeatable
• Local (i.e. Fast)
• Host-OS agnostic
36. 使⽤用 VM 的好處
• Isolated
• Repeatable
• Local (i.e. Fast)
• Host-OS agnostic
• Anyone can do it (Faster on-boarding)
37. 使⽤用 VM 的好處
• Isolated
• Repeatable
• Local (i.e. Fast)
• Host-OS agnostic
• Anyone can do it (Faster on-boarding)
• Less bugs
40. Vagrant
• Vagrant uses VirtualBox to build configurable,
lightweight, and portable virtual machines
dynamically
• Open Source: MIT license
• It support more providers recently:
• VMware Fusion
• AWS EC2
• Rackspace
41. The creator
• Mitchell Hashimoto
• 從 2010 年開始
• 2012/11 成⽴立 Hashicorp 公司作商業⽀支
持,並提供更多(付費) Providers,包括
VMware Fusion, Workstation 和 vSphere 等
等。
42. Who use it?
• Mozilla, Firefox
• BBC News
• New York Times
• Openstack
• NOKIA
• Livingsocial
• yammer
• shopify
• disqus
• eventbrite
• ngmoco
46. Warning for
Ruby developers
• Vagrant 1.1+ 之後不⽤用 rubygems 安裝了
• 主要理由: For non-rubyist
• http://mitchellh.com/abandoning-rubygems
47. 從現有的專案開 VM
• git clone git://github.com/eduvo/pair_tdd_get_started.git
• vagrant up
• 可以開始寫 Ruby 了
48. Live Demo
請不要在會場做
第⼀一次跑需要下載 VM image, 306mb
49. 新開⼀一個 Ubuntu VM
• vagrant box add precise64
http://files.vagrantup.com/precise64.box
• mkdir my_box
• cd my_box
• vagrant init precise64
• vagrant up
50. Demo
真的,請不要在會場做
第⼀一次跑需要下載 VM image, 306mb
51. VM Lifecycle
(基本指令)
• vagrant up 開機
• vagrant ssh 登⼊入
• vagrant suspend 暫停
• vagrant halt 關機
• vagrant destroy 刪除
54. Base Boxes
• 開 VM 的基本 image
• box 是⼀一個檔案
• Vagrant 是 project-oriented,在 project 裡
⾯面玩,不影響 Box。
• 官⽅方有包 Ubuntu 10.04/12.04, 32bit/64bit
for VirtualBox 的 boxes
• 更多第三⽅方 http://vagrantbox.es
58. Host OS v.s. Guest VM
Host OS
Guest VM Guest VM Guest VM
64. Shared folder
config.vm.share_folder "foo", "/guest/path", "/host/path",
:nfs => true
• 在 host 和 guest 之間共享檔案
• 例如開發⽤用 Editor 在 host 跑,但是程式
是在 guest 裡執⾏行
• 預設 guest 裡的 /vargant 就是專案⺫⽬目錄
• VirtualBox shared folder 效能差,Vagrant
⽀支援 NFS
66. Networking
以下三種可以依照需求選擇使⽤用,都⽤用也可以
• Port forwarding
• Host-only networking
• Bridged Networding
73. Server provisioning
• Server provisioning is a set of actions to
prepare a server with appropriate systems,
data and software, and make it ready for
network operation. (from wikipedia)
74. Server provisioning
• Server provisioning is a set of actions to
prepare a server with appropriate systems,
data and software, and make it ready for
network operation. (from wikipedia)
• 就是裝 server 啦
76. Old-school
I’m System Administrator
• 寫⽂文件,照著作
77. Old-school
I’m System Administrator
• 寫⽂文件,照著作
• "multi-terminal",開⼀一個視窗打指令,同
時好幾個 servers 都會執⾏行
78. Old-school
I’m System Administrator
• 寫⽂文件,照著作
• "multi-terminal",開⼀一個視窗打指令,同
時好幾個 servers 都會執⾏行
• 建⽴立 .iso image 以便拷⾙貝新機器
79. Old-school
I’m System Administrator
• 寫⽂文件,照著作
• "multi-terminal",開⼀一個視窗打指令,同
時好幾個 servers 都會執⾏行
• 建⽴立 .iso image 以便拷⾙貝新機器
• 缺點:版本維護
85. Old-school (cont.)
• 撰寫 setup shell script
• 缺點: shell script 不聰明,不好維護
• 再跑⼀一次會裝第⼆二次
• 套件之間的 dependency 關係
• 套件的設定檔要如何管理?
90. Modern provisioning
I’m DevOps
• 利⽤用 Configuration Management tools
• Chef
• Puppet
• CFEngine
91. Modern provisioning
I’m DevOps
• 利⽤用 Configuration Management tools
• Chef
• Puppet
• CFEngine
• 撰寫 recipe (Chef) 或 manifest (Puppet) 設定要裝
什麼東⻄西
92. Modern provisioning
I’m DevOps
• 利⽤用 Configuration Management tools
• Chef
• Puppet
• CFEngine
• 撰寫 recipe (Chef) 或 manifest (Puppet) 設定要裝
什麼東⻄西
• receipt 和 manifests 可以重複執⾏行,保持 server
到最新版。不會發⽣生重裝第⼆二遍的情形。
98. Vagrant ⽀支援
⽅方便 DevOps 測試 Recipe
• shell
• Chef
• Puppet
• CFEngine
100. Chef Example
package "nginx"
service "nginx" do
supports :status => true, :restart => true, :reload => true
action [:enable, :start]
end
template "/etc/nginx/nginx.conf" do
source "nginx.conf.erb"
notifies :reload, "service[nginx]"
end
103. 將⺫⽬目前的 VM 打包成 Box
• vagrant package 產⽣生 package.box 檔案
• vagrant box add <name> package.box
• 使⽤用時機
• Package up installed software
• Use provisioners for configuration and
managing services
105. Multi-VM
• 同⼀一個 Vagrantfile 可以設定多個 VM
• vagrant up 就會同時開起來
• 適合 distributed 和 SOA 開發環境
• ⼀一台 Web server
• 多台 Application servers
• ⼀一台 Database server
106. Vagrantfile example
指定IP,VMs 之間也可以互通
Vagrant.configure("2") do |config|
config.vm.define :web do |web|
web.vm.box = "precise64"
web.vm.network :private_network, :ip => "192.168.33.11"
end
config.vm.define :app do |app|
app.vm.box = "precise64"
app.vm.network :private_network, :ip => "192.168.33.12"
end
config.vm.define :db do |db|
db.vm.box = "precise64"
db.vm.network :private_network, :ip => "192.168.33.13"
end
end
110. AWS
• 同樣的 vagrant up 指令,可以開 VM 在 EC2 或 VPC 上
• 使⽤用情境:
• 可以開運算能⼒力的 EC2 機器作開發或測試運算
• 可以開真正 production 使⽤用的機器作測試
• 從開發、staging 到 production,都⽤用 vagrant 開 VM
管理
• 無論 providers,Vagrantfile 皆共⽤用
113. Conclusion
使⽤用情境
• DevOps 開發和測試 Chef/Puppet/etc.
scripts
114. Conclusion
使⽤用情境
• DevOps 開發和測試 Chef/Puppet/etc.
scripts
• WebDev 可以使⽤用上述 DevOps 開發的
scripts 安裝出⾮非常接近 production 的開
發環境
115. Conclusion
使⽤用情境
• DevOps 開發和測試 Chef/Puppet/etc.
scripts
• WebDev 可以使⽤用上述 DevOps 開發的
scripts 安裝出⾮非常接近 production 的開
發環境
• QA 測試⼯工程師可以使⽤用 CI 搭配 Vagrant
來建構⾃自動化的部署測試、⼤大規模的 test
environment 等等
117. 謝謝!
Thank you!
(對 Vagrant 或 Chef 有問題歡迎來 Faria 攤位找我們的 DevOps: Vincent)
118. References
• http://www.hashicorp.com/blog
• http://net.tutsplus.com/tutorials/php/vagrant-what-why-
and-how/
• O'Reilly Velocity 2012: Develop and Test Configuration
Management Scripts with Vagrant
• LARubyconf 2011: Working in Vurtual Machines-The
Vagrant Way
• ChefConf 2012: http://confreaks.com/videos/1672-
chefconf2012-consistent-local-development-with-vagrant-
and-chef