Share
Embed
Transcript
46 slides
-
ϓϩϏδϣχϯάπʔϧ • CFEngine • Puppet • Chef • Ansible •
Saltstack • Itamae7←7NEW!! 3 -
Chefͬͯʁ • αʔόߏཧπʔϧ • Ruby&DSLʹΑΔߴ͍දݱྗ • ڊେͳΤίγεςϜɾπʔϧ܈ • knife,&berkshelfͳͲͳͲ •
Ϣʔβଟ͘ɺॻ੶ɾϒϩάهࣄͳͲ๛ 5 -
Ͱ… • ֶशίετ͕ߴ͍ʢͱݴΘΕ͍ͯΔʣ • ػೳ๛Ͱศརͳ໘ɺ֮͑Δ͜ͱଟ͍ • খ࢝͘͞Ίͨͯ͘େ͖͘ͳΓ͕ͪ • σΟϨΫτϦɺϑΝΠϧɺϨϙδτϦͷࢁ… •
ϋϚΓͲ͜Ζଟ͍ʢͱࢥ͏ʣ • BerkshelfͷϏϧυʹࣦഊͨ͠Γ…ʢChef,DK 6 -
ͦ͜ͰɺItamae • ֶ͍शίετ • ࠓ͢͜ͱ͕Itamaeͷ΄΅ͯ͢ • ݴ͍͑Εɺػೳ͔ͳΓগͳ͍ • ͕ɺ࠷ݶͷػೳἧ͍ͬͯΔ •
ChefͬΆ͍ૉఢͳRuby.DSL͕͔ͭ͑Δ • YAMLʁ͍͑ɺΒͳ͍ࢠͰ͢Ͷ 7 -
Chef%&>%Itamae • cookbooks • recipes • roles • environments •
Chef3Server • Berkshelf 8 -
Chef%&>%Itamae • cookbooks • recipes • roles • environments •
Chef3Server • Berkshelf 9 -
͍ํ 1.#ϨγϐΛॻ͘ # nginx.rb service "nginx" # nginxΛΠϯετʔϧ͢Δ package "nginx"
template "/etc/nginx/nginx.conf" do source "nginx.conf.erb" # ઃఆϑΝΠϧ͕ߋ৽͞ΕͨΒɺnginxΛϦϩʔυ͢Δ notifies :reload, "service[nginx]" end 11 -
SSH͝͠ʹ࣮ߦͰ͖Δ $ itamae ssh -h 192.168.10.10 \ -p 22 -u
user recipe.rb VagrantͰಈ͍͍ͯΔVMʹͭͳ͙ $ vagrant up $ itamae ssh --vagrant -h vm_name recipe.rb VagrantϓϥάΠϯͷvagrant(itamaeΛ͏ख 13 -
͚ͬ͜͏͍ܰ $ time sudo chef-solo -c solo.rb -j node.json Recipe:
hello::default * execute[echo Hello] action run - execute echo Hello 1.70s user 0.74s system 71% cpu 3.414 total $ time itamae local hello/recipes/default.rb INFO : Recipe: /private/tmp/... INFO : execute[echo Hello] INFO : action: run 0.33s user 0.12s system 87% cpu 0.516 total # ͜ͷ߹ɺItamaeOhaiΛୟ͍ͯͳ͍ͷͰͪΐͬͱνʔτͬΆ͍ 15 -
͚ͬ͜͏খ͍͞ $ gem i itamae --pre Successfully installed thor-0.19.1 Successfully
installed net-scp-1.2.1 Successfully installed specinfra-2.0.0.beta43 Successfully installed hashie-3.3.1 Successfully installed ansi-1.4.3 Successfully installed itamae-1.0.0.beta50 6 gems installed 16 -
remote_file,*template*Ϧιʔε remote_fileChefͰ͍͏cookbook_file remote_file "/etc/nginx/nginx.conf" do # ϨγϐϑΝΠϧ͔Βͷ૬ରύε source "nginx.conf" end
template "/etc/nginx/nginx.conf" do # ϨγϐϑΝΠϧ͔Βͷ૬ରύε source "nginx.conf.erb" variables(server_name: "itamae.kitchen") end 20 -
ڞ௨Ͱ͑ΔΞτϦϏϡʔτ package "sl" do # ΞΫγϣϯ action :install # ͋ΔίϚϯυ͕ޭ͚ͨ࣌ͩ͠
only_if "test -e /tmp/you_like_sl" # ͋ΔίϚϯυ͕ࣦഊ͚ͨ࣌ͩ͠ not_if "test -e /tmp/you_do_not_like_sl" # ࣮ߦϢʔβ user "myuser" end 22 -
no#fies Ϧιʔε͕ߋ৽͞Εͨʢύοέʔδ͕Πϯετʔϧ ͞ΕͨɺͳͲʣ߹ʹɺଞͷϦιʔεͷΞΫγϣϯ Λ࣮ߦ͢Δ service "nginx" template "/etc/nginx/conf.d/site" do source
"nginx/site.erb" notifies :reload, "service[nginx]" end 24 -
subscribes ଞͷϦιʔε͕ߋ৽͞Εͨʢύοέʔδ͕Πϯε τʔϧ͞ΕͨɺϑΝΠϧ͕ॻ͖Θͬͨetc.ʣ߹ ʹɺΞΫγϣϯΛ࣮ߦ͢Δ service "nginx" do subscribes :reload, "template[/etc/nginx/conf.d/site]"
end template "/etc/nginx/conf.d/site" do source "nginx/site.erb" end 25 -
defini&on ෳͷϦιʔε͔Β৽͍͠ϦιʔεΛఆٛ͢Δ define :install_and_enable_package, version: nil do package params[:name] do
version params[:version] if params[:version] action :install end service params[:name] do action :enable end end install_and_enable_package 'nginx' do version '1.6.1' end 26 -
include_recipe Ϩγϐ͔ΒଞͷϨγϐΛݺͼग़͢ # nginx.rb package "nginx" template "/etc/nginx/conf.d/hello" do source
"nginx.erb" end # sl.rb package "sl" # web_server.rb include_recipe "nginx.rb" include_recipe "sl.rb" 27 -
ϊʔυΞτϦϏϡʔτ • itamae -j node.jsonͳͲͱJSONϑΝΠϧΛ ࢦఆ͢Δͱ • ϨγϐςϯϓϨʔτͰnode[:key]ͷΑ͏ʹ ࢀরͰ͖Δ $
echo '{"nginx": {"domain": "itamae.kitchen"}}' \ > node.json $ itamae local -j node.json your_recipe.rb 29 -
OhaiΠϯςάϨʔγϣϯ Ohai? $ ohai | head { "cpu": { "real":
4, "total": 8, "mhz": 2600, "vendor_id": "GenuineIntel\n", "model_name": "Intel(R) ...", "model": 70, "family": 6, "stepping": 1, 31 -
OhaiΠϯςάϨʔγϣϯ ྫ # bundle.rb execute "bundle install -j #{node[:cpu][:total]}" $
itamae local --ohai bundle.rb 32 -
ϨγϐϓϥάΠϯ • ϨγϐΛGemʹด͡ࠐΊΔ͜ͱ͕Ͱ͖Δ • BundlerͰґଘཧʂʢBerkshelfෆཁʣ # Gemfile gem 'itamae-plugin-recipe-selinux' #
your_recipe.rb include_recipe 'selinux::enforcing' $ bundle exec itamae your_recipe.rb 34 -
ϦιʔεϓϥάΠϯ • ࣗ༝ʹϦιʔεΛఆٛͯ͠GemͰϓϥάΠϯ͔Ͱ ͖Δ # Gemfile gem 'itamae-plugin-resource-mail_alias' # your_recipe.rb
mail_alias "alias_name" do recipient "recipient_name" end $ bundle exec itamae your_recipe.rb 35 -
࣮ͷ • mizzy͞Μ࡞ͷSpecinfra1ʹ͔͍ͬͬͯΔ • backend:3ڞ௨ͷΠϯλʔϑΣʔεͰίϚϯυΛ ࣮ߦͰ͖ΔʢLocal,3SSHͳͲʣ • command:3OS͝ͱʹίϚϯυΛੜͯ͘͠ΕΔ `install_package('sl') #=>3"aptFget3install3sl"
1"h$ps:/ /github.com/serverspec/specinfra 36 -
Itamae&in&Produc/on • ΫοΫύουͷຊ൪ڥͰӡ༻͞Ε͍ͯΔ • ݱ࣌Ͱ30͙Β͍ItamaeΛͬͯߏங͞Εͯ ͍Δ • ItamaeࣗମϨγϐΛࢦఆͯ͠ɺ࣮ߦ͢Δػೳ͠ ͔༻ҙ͍ͯ͠ͳ͍ •
ΫοΫύουͰCapistranoͰItamaeΛୟ͍͍ͯ Δ 38 -
Itamae&in&Produc/on • cap itamaeͰ • αʔόͷϩʔϧʹԠͨ͡ϨγϐΛrsyncͯ͠ • itamaeίϚϯυΛ࣮ߦ͢Δ • Itamaeʹϩʔϧͱ͍͏֓೦ͳ͍
• ͕ɺಉ͡Α͏ͳ͜ͱΛϨγϐͰ࣮ݱ͍ͯ͠Δ 39 -
Itamae&in&Produc/on webϩʔϧΛ༻ҙͯ͠ΈΔ # recipes/nginx.rb package "nginx" # recipes/sl.rb package "dstat"
# roles/web.rb include_recipe "../recipes/nginx.rb" include_recipe "../recipes/dstat.rb" 40 -
Itamae&in&Produc/on # config/deploy/itamae.rb task :apply do # 1. ͍͍ײ͡ʹΛऔ͖ͬͯͯnode.jsonΛஔ͘ #
2. Ϩγϐͱ͔/tmp/itamaeʹrsync͓ͯ͘͠ # 3. ϩʔϧΛEC2ͷλάͳͲ͔Βऔಘ͢Δ role_recipe = "/tmp/itamae/roles/#{role}.rb" sudo "itamae", "local", "-j", "node.json", role_recipe end $ cap itamae apply HOSTS=your-web-server 41