Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Vagrant基礎

 Vagrant基礎

社内勉強会用の資料です

Takuya Arita

May 17, 2016
Tweet

More Decks by Takuya Arita

Other Decks in Technology

Transcript

  1. ΞδΣϯμ • Vagrantͱ͸ • Vagrantͷ࢖͍ํ • Vagrantfile • Box, ϓϩϏδϣχϯά,

    ϓϥάΠϯ • Vagrantͷ࢖͍ํ Ԡ༻ฤ • VagrantΛ࢖͏্Ͱͷ஫ҙ఺
  2. Vagrantͷ࢖͍ํ $ vagrant init ubuntu/trusty64 $ # ↑ Ubuntu 14.04ͷԾ૝ϚγϯΛ࡞ΔͨΊͷVagrantfileΛੜ੒

    $ vagrant up # Vagrantfileͷهड़ʹج͍ͮͯVMΛ࡞੒(ॳճͷΈ)ɺىಈ $ vagrant ssh # VMʹSSH઀ଓ $ vagrant reload # VMΛ࠶ىಈ $ vagrant halt # VMΛऴྃ $ vagrant destroy # VMΛഁغ
  3. VagrantfileͰΑ͘࢖͏߲໨ • config.vm.box • ࢖༻͢ΔBox(ޙड़)ͷछྨΛઃఆ͢Δ • config.vm.network • VMͷωοτϫʔΫઃఆΛ௥Ճ͢Δ •

    Vagrant͸σϑΥϧτͰϗετͷ2222൪ϙʔτΛήετͷ22൪ϙʔτʹϙʔ τϑΥϫʔυ͢Δ(ॏෳͨ͠৔߹͸2200Ҏ߱ͷ࿈൪͕࢖༻͞ΕΔ) • ϙʔτϑΥϫʔυͰ͸80൪ͳͲͷWell-knownϙʔτΛ࢖༻͢Δࡍʹϗετͷ ؅ཧݖݶ͕ཁٻ͞ΕΔͨΊɺ͜ͷઃఆͰผͷIPΞυϨεΛ෇༩͢Δ͜ͱ͕ଟ͍
  4. VagrantfileͰΑ͘࢖͏߲໨ • config.vm.synced_folder • VirtualBoxͷڞ༗ϑΥϧμػೳΛ࢖༻͠ɺήετ͔ΒϗετͷσΟϨΫτϦΛϚ΢ϯτ͢ΔઃఆΛ௥Ճ Ͱ͖Δ • σϑΥϧτͰ͸Vagrantfile͕഑ஔ͞Ε͍ͯΔσΟϨΫτϦ͕ήετͷ/vagrantʹϚ΢ϯτ͞Ε͍ͯΔ ͕ɺ͜ͷઃఆΛ௥Ճ͢Δ͜ͱͰɺϗετଆͷଞͷσΟϨΫτϦ΋Ϛ΢ϯτͰ͖Δ •

    config.vm.provider • VMʹׂΓ౰ͯΔϦιʔεͷઃఆΛ͢ΔɻΑ͘࢖͏ͷ͸ҎԼͷ2ͭ • vb.memory: VMʹׂΓ౰ͯΔϝϞϦ༰ྔɻσϑΥϧτ͸512M͕ͩେମ1G͸ඞཁʹͳΓ͕ͪ • vb.cpus: VMʹׂΓ౰ͯΔԾ૝CPU਺ɻσϑΥϧτͷ1Ҏ্ʹ͢Δ͜ͱ͸࣮຿্গͳ͍͕ɺن໛ͷେ ͖ͳϓϩδΣΫτ΍ɺGUIͰ࢖༻͢Δ৔߹͸ଟΊʹ͢Δ͜ͱ΋͋Δ • config.vm.provision: ϓϩϏδϣχϯάͷઃఆ(ޙड़)
  5. ϓϩϏδϣχϯά • VMߏங࣌ͳͲʹॳظઃఆΛ͢ΔͨΊͷखଓ͖Λهड़Ͱ͖Δ • vagrant upͷॳճ࣮ߦ࣌΍vagrant provision࣮ߦ࣌ʹ࣮ߦ͞Ε Δ • vagrant

    up —no-provisionͰϓϩϏδϣχϯάΛ࣮ߦͤͣ ʹVMΛߏங͢Δ͜ͱ΋Մೳ • γΣϧεΫϦϓτ΍ChefɺAnsibleͳͲͷϓϩϏδϣχϯάπʔ ϧ(Provisioner)ʹରԠ͍ͯ͠Δ
  6. ͓͢͢ΊϓϥάΠϯ • vagrant-pristine • https://github.com/fgrehm/vagrant-pristine • vagrant pristineͱ͍͏αϒίϚϯυΛ௥Ճ͢ΔϓϥάΠϯɻdestroyͱupΛಉ࣌ ʹ࣮ߦͰ͖ΔͷͰɺ։ൃ؀ڥΛԿ౓΋࡞Γͳ͓࣌͢ʹ࢖͏ •

    vagrant-vbguest • https://github.com/dotless-de/vagrant-vbguest • VirtualBoxͷGuest AdditionsΛߋ৽͢ΔͷʹศརͳϓϥάΠϯ • ͨ·ʹGuest Additions͕ݹ͍͜ͱ͕ݪҼͰڞ༗σΟϨΫτϦ͕Ϛ΢ϯτͰ͖ͳ ͔ͬͨΓ͢ΔͷͰɺ೥ʹ1ճ͙Β͍࢖͏͜ͱ΋͋Δ
  7. Vagrantͷ࢖͍ํ Ԡ༻ฤ • vagrant snapshot [push|pop|save|restore] • ͦͷ࣌఺ͷVMΠϝʔδͷεφοϓγϣοτΛऔಘ͢Δ • pushͰεφοϓγϣοτΛελοΫʹ௥ՃɺpopͰελο

    Ϋ͔ΒऔΓग़ͯ͠ϦετΞ • saveͰ໊લΛ͚ͭͯอଘɺrestoreͰ໊લΛࢦఆͯ͠εφο ϓγϣοτΛϦετΞ • ϓϩϏδϣχϯάͷ֬ೝ΍େ͖ͳมߋΛ͢Δ·͑ʹศར
  8. Vagrantͷ࢖͍ํ Ԡ༻ฤ • vagrant share • ϩʔΧϧͰߏஙͨ͠VMΛΠϯλʔωοτ্ʹެ։Ͱ͖Δ • HTTP, HTTPS,

    SSHʹରԠ • AtlasͷϢʔβʔొ࿥͕ඞཁ • LTE/3G؀ڥͷεϚʔτϑΥϯͰͷ࣮ػςετͳͲͰศར • खݩͷ؀ڥ͕Πϯλʔωοτ্ʹެ։͞ΕΔ͜ͱΛ౿·͑ͯɺBasicೝ ূ΍IP੍ݶΛઃఆͯ͠࢖͏
  9. VagrantΛ࢖͏্Ͱͷ஫ҙ఺ • ڞ༗ϑΥϧμ(/vagrant)͸஗͍ • Vagrantͷ໰୊Ͱ͸ͳ͍͕ɺVirtualBoxͷڞ༗ϑΥϧμ͸ಡΈॻ͖ͱ ΋ʹ஗͍ • ڞ༗ϑΥϧμͷݖݶʹؾΛ͚ͭΔ • /vagrantͷݖݶ͸σϑΥϧτͰvagrant:vagrant

    0755ͱͳ͍ͬͯΔ • ڞ༗ϑΥϧμʹWebΞϓϦΛ഑ஔ͢Δͱ͖ɺσϑΥϧτͷઃఆͩͱ ϩάΛॻ͖ࠐΊͳͯ͘ࠔΔ͜ͱ͕͋ΔͷͰɺͦͷ৔߹͸ڞ༗ϑΥϧ μͷϚ΢ϯτΦϓγϣϯΛద੾ʹઃఆ͢Δ