Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Vagrant基礎
Search
Takuya Arita
May 17, 2016
Technology
0
170
Vagrant基礎
社内勉強会用の資料です
Takuya Arita
May 17, 2016
Tweet
Share
More Decks by Takuya Arita
See All by Takuya Arita
Hosted Redash の EOL と移行ツール redash-migrate / You should know about Hosted Redash EOL and redash-migrate
ariarijp
0
3k
Redash で踏み出す BI 導入はじめの一歩 / DataEngineeringStudy Redash
ariarijp
1
2.1k
Redash のいま / Redash in 2021
ariarijp
2
1k
Redash 導入・運用を4年ぐらいやって変わったこと・変わらなかったこと / Changed and unchanged things with Redash and me
ariarijp
0
1.3k
5年前の自分に伝えたい広告 API 周辺の歩き方 / SOT Tech Night vol.1
ariarijp
1
470
使われていない、を知る / How do we know unused things in the real world?
ariarijp
0
390
MULTI_ORG について / What is MULTI_ORG in Redash
ariarijp
1
3.4k
あらためて振り返る Redash の使いどころ / Why I strongly recommend Redash
ariarijp
2
1.2k
PHP Data Structures
ariarijp
1
510
Other Decks in Technology
See All in Technology
【re:Invent 2024 アプデ】 Prompt Routing の紹介
champ
0
160
Opcodeを読んでいたら何故かphp-srcを読んでいた話
murashotaro
0
320
最近のSfM手法まとめ - COLMAP / GLOMAPを中心に -
kwchrk
3
470
非機能品質を作り込むための実践アーキテクチャ
knih
5
1.6k
2024年にチャレンジしたことを振り返るぞ
mitchan
0
150
私なりのAIのご紹介 [2024年版]
qt_luigi
1
120
DUSt3R, MASt3R, MASt3R-SfM にみる3D基盤モデル
spatial_ai_network
2
270
ゼロから創る横断SREチーム 挑戦と進化の軌跡
rvirus0817
3
280
LINE Developersプロダクト(LIFF/LINE Login)におけるフロントエンド開発
lycorptech_jp
PRO
0
150
10個のフィルタをAXI4-Streamでつなげてみた
marsee101
0
180
Working as a Server-side Engineer at LY Corporation
lycorp_recruit_jp
0
380
普通のエンジニアがLaravelコアチームメンバーになるまで
avosalmon
0
120
Featured
See All Featured
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
45
2.2k
Music & Morning Musume
bryan
46
6.2k
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
29
910
Bootstrapping a Software Product
garrettdimon
PRO
305
110k
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
127
18k
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
251
21k
Understanding Cognitive Biases in Performance Measurement
bluesmoon
26
1.5k
Side Projects
sachag
452
42k
Facilitating Awesome Meetings
lara
50
6.1k
Designing on Purpose - Digital PM Summit 2013
jponch
116
7k
The Straight Up "How To Draw Better" Workshop
denniskardys
232
140k
Cheating the UX When There Is Nothing More to Optimize - PixelPioneers
stephaniewalter
280
13k
Transcript
Vagrantجૅ @ariarijp
ఆϦεφʔ • VagrantΛͬͨ͜ͱ͕͋Δɺݱࡏ͍ͬͯΔ • vagrant up/ssh/reload/halt͙Β͍ͬͨ͜ͱ͕͋Δ • ݴΘΕΔ͕··ʹ͍ͬͯΔ͕ɺ࣮Α͘Θ͔͍ͬͯͳ ͍Α͏ͳؾ͕͢Δ •
VagrantfileͬͯԿͩΖ͏ʁԿ͕Ͱ͖ΔΜͩΖ͏ʁͱࢥͬ ͍ͯΔ
ΞδΣϯμ • Vagrantͱ • Vagrantͷ͍ํ • Vagrantfile • Box, ϓϩϏδϣχϯά,
ϓϥάΠϯ • Vagrantͷ͍ํ Ԡ༻ฤ • VagrantΛ͏্Ͱͷҙ
Vagrantͱ • Hashicorp͕ఏڙ͍ͯ͠Δ։ൃڥͷߏஙπʔϧ • VirtualBoxVMwareͳͲͷԾԽϨΠϠ্ʹίϚϯυϥΠϯૢ࡞Ͱ ԾϚγϯ(VM)Λߏங͢Δ͜ͱ͕Ͱ͖Δ • RubyͰॻ͔Ε͍ͯͯϓϥάΠϯ(ޙड़)Ͱ֦ுՄೳ • Windows/Mac/LinuxͷϚϧνϓϥοτϑΥʔϜͰಈ࡞͢Δ
• 2013͝Ζ͔Β͘ར༻͞Ε࢝ΊɺݱࡏͰΑ͘ΘΕΔπʔϧͷ ͻͱͭ
Vagrantͷಋೖ • VagrantຊମHashicorpͷެࣜαΠτ͔Βμϯ ϩʔυ͢Δͷ͕ਖ਼ಓ • https://www.vagrantup.com/downloads.html • ԾԽϨΠϠͱͯ͠VirtualBox͕ΘΕΔ͜ͱ͕ ଟ͍ •
https://www.virtualbox.org/
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Λഁغ
Vagrantfile • ͲΜͳVMΛߏங͍ͨ͠ͷ͔Λهड़͢ΔϑΝΠϧ • ࣮ଶRubyͷεΫϦϓτ • ͜ͷΑ͏ʹಛఆͷ༻్(͜͜ͰVagrantʹΑΔ VMͷߏங)ʹಛԽͨ͠هड़ݴޠDSL(Domain Specific Language)ͱݺΕΔ
VagrantfileͰΑ͘͏߲ • config.vm.box • ༻͢ΔBox(ޙड़)ͷछྨΛઃఆ͢Δ • config.vm.network • VMͷωοτϫʔΫઃఆΛՃ͢Δ •
VagrantσϑΥϧτͰϗετͷ2222൪ϙʔτΛήετͷ22൪ϙʔτʹϙʔ τϑΥϫʔυ͢Δ(ॏෳͨ͠߹2200Ҏ߱ͷ࿈൪͕༻͞ΕΔ) • ϙʔτϑΥϫʔυͰ80൪ͳͲͷWell-knownϙʔτΛ༻͢Δࡍʹϗετͷ ཧݖݶ͕ཁٻ͞ΕΔͨΊɺ͜ͷઃఆͰผͷIPΞυϨεΛ༩͢Δ͜ͱ͕ଟ͍
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: ϓϩϏδϣχϯάͷઃఆ(ޙड़)
Box • VMͷςϯϓϨʔτͷΑ͏ͳͷ • Atlasͱ͍͏αʔϏεͰެ։͞Ε͍ͯΔΠϝʔδΛݕࡧͰ͖ɺBox Atlas͔ΒμϯϩʔυͰ͖Δ • Packer(Hashicorp)ͳͲΛ༻ͯࣗ͠࡞͢Δ͜ͱՄೳ • Atlas্Ͱࣗ࡞ͷΠϝʔδΛެ։͢Δ͜ͱՄೳ
• ۀͰΔ͜ͱ΄΅ͳ͍͕ɺBoxΛAtlasͳͲͰެ։͠ɺಋೖ(ओ ʹࢼ༻ͷͨΊ)Λ༰қʹ͍ͯ͠ΔOSSϓϩμΫτଟ͍
ϓϩϏδϣχϯά • VMߏங࣌ͳͲʹॳظઃఆΛ͢ΔͨΊͷखଓ͖Λهड़Ͱ͖Δ • vagrant upͷॳճ࣮ߦ࣌vagrant provision࣮ߦ࣌ʹ࣮ߦ͞Ε Δ • vagrant
up —no-provisionͰϓϩϏδϣχϯάΛ࣮ߦͤͣ ʹVMΛߏங͢Δ͜ͱՄೳ • γΣϧεΫϦϓτChefɺAnsibleͳͲͷϓϩϏδϣχϯάπʔ ϧ(Provisioner)ʹରԠ͍ͯ͠Δ
ϓϩϏδϣχϯά • ؆୯ͳઃఆShell ProvisionerΛ͏ • ͍͍ͩͨ͜ΕͰͳΜͱ͔ͳΔ • ෳࡶͳઃఆ͕ඞཁͳ߹ɺطଘͷϦιʔεΛྲྀ༻͢Δ߹Chefͳ ͲͷProvisionerΛ͏ͷͰͳ͘ɺVMʹChefAnsibleΛಋೖ͠ɺ VMͰͦΕΒΛ࣮ߦ͢ΔΑ͏ͳॲཧΛShell
ProvisionerͰهड़͢Δͷ ͕͓͢͢Ί • Chef ProvisionerͳͲΛ͏ͱϗετଆͷڥΛߟྀ͠ͳͯ͘ͳ Βͳ͍(ಛʹWindows/Mac͕ͭΒ͍
ϓϥάΠϯ • VagrantʹػೳΛՃ͢ΔΈͰɺଟ͘ͷϓ ϥάΠϯ͕ެ։͞Ε͍ͯΔ • https://github.com/mitchellh/vagrant/wiki/ Available-Vagrant-Plugins • vagrant plugin
install vagrant-pristineͷΑ͏ ʹvagrantίϚϯυͰಋೖͰ͖Δ
͓͢͢ΊϓϥάΠϯ • 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ճ͙Β͍͏͜ͱ͋Δ
Vagrantͷ͍ํ Ԡ༻ฤ • vagrant snapshot [push|pop|save|restore] • ͦͷ࣌ͷVMΠϝʔδͷεφοϓγϣοτΛऔಘ͢Δ • pushͰεφοϓγϣοτΛελοΫʹՃɺpopͰελο
Ϋ͔ΒऔΓग़ͯ͠ϦετΞ • saveͰ໊લΛ͚ͭͯอଘɺrestoreͰ໊લΛࢦఆͯ͠εφο ϓγϣοτΛϦετΞ • ϓϩϏδϣχϯάͷ֬ೝେ͖ͳมߋΛ͢Δ·͑ʹศར
Vagrantͷ͍ํ Ԡ༻ฤ • vagrant share • ϩʔΧϧͰߏஙͨ͠VMΛΠϯλʔωοτ্ʹެ։Ͱ͖Δ • HTTP, HTTPS,
SSHʹରԠ • AtlasͷϢʔβʔొ͕ඞཁ • LTE/3GڥͷεϚʔτϑΥϯͰͷ࣮ػςετͳͲͰศར • खݩͷڥ͕Πϯλʔωοτ্ʹެ։͞ΕΔ͜ͱΛ౿·͑ͯɺBasicೝ ূIP੍ݶΛઃఆͯ͠͏
VagrantΛ͏্Ͱͷҙ • ͳΔ͘ϓϩϏδϣχϯάΛ͏ • ͲΜͳখ͞ͳϓϩδΣΫτͰڥߏஙࣗಈԽ ͠ɺ͔ͭɺ࠶ݱੑ͕͋Δܗʹ͢Δ • VMϓϩδΣΫτ୯ҐͳͲͰ͚Δ • ͻͱͭͷVMʹ͍Ζ͍ΖಥͬࠐΜͰ͠·͏ͱͤͬ
͔͘VMͷཧָ͕ʹͳΔ͏·Έ͕ͳ͍
VagrantΛ͏্Ͱͷҙ • ڞ༗ϑΥϧμ(/vagrant)͍ • VagrantͷͰͳ͍͕ɺVirtualBoxͷڞ༗ϑΥϧμಡΈॻ͖ͱ ʹ͍ • ڞ༗ϑΥϧμͷݖݶʹؾΛ͚ͭΔ • /vagrantͷݖݶσϑΥϧτͰvagrant:vagrant
0755ͱͳ͍ͬͯΔ • ڞ༗ϑΥϧμʹWebΞϓϦΛஔ͢Δͱ͖ɺσϑΥϧτͷઃఆͩͱ ϩάΛॻ͖ࠐΊͳͯ͘ࠔΔ͜ͱ͕͋ΔͷͰɺͦͷ߹ڞ༗ϑΥϧ μͷϚϯτΦϓγϣϯΛదʹઃఆ͢Δ
VagrantΛ͏্Ͱͷҙ • VM݁ߏϦιʔεΛফඅ͢Δ • 1ϓϩδΣΫτͰVMΛ2ͭىಈͨ͠Γ͢Δ͜ͱ͋Δ͕ɺಛʹϝ ϞϦͱσΟεΫ༰ྔʹҙ • τϥϒϧʹૺ۰ͨ࣌͠ͷͨΊʹVirtualBox୯ମͰ͔ͭ͏ํ๏ͬ ͓ͯ͘ •
vagrant upͨ͠Βɺͳ͔ͥਅ৽͍͠VM͕ىಈ͞ΕͨΓ͢Δ͜ͱ ͋ΔͷͰɺͦ͏͍ͬͨ߹ʹରॲ͢ΔͨΊʹVirtualBoxͷ ͕ࣝଟগ͋Δͱ·͍͠
·ͱΊ • ࠓ·Ͱ͋·Γҙ͍ࣝͯͬͯ͠ͳ͔ͬͨVagrant࣮͍Ζ ͍Ζͳ͍ํઃఆ͕͋Γ·͢ • ಛʹɺ͜Ε͔ΒࣗͰ։ൃڥΛߏங͢ΔΑ͏ʹͳΔͱɺ Vagrantͱͯڧྗͳಓ۩ʹͳΔͷͰɺࢥͬͨ௨ΓͷڥͰ ࡞ۀ͕Ͱ͖ΔΑ͏ʹ͍ํΛ͍͖֮͑ͯ·͠ΐ͏ • VagrantΛ׆༻͢Δʹ(ಛʹϓϩϏδϣχϯά͋ͨΓͰ)Linux
ͷ͕ࣝඞਢʹͳΓ·͢ɻ͋Θ͍͖֮ͤͯ͑ͯ·͠ΐ͏