Tải bản đầy đủ (.pdf) (426 trang)

Vagrant virtual development environment cookbook by chad thompson

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (10.86 MB, 426 trang )



VagrantVirtualDevelopment
EnvironmentCookbook


TableofContents
VagrantVirtualDevelopmentEnvironmentCookbook
Credits
AbouttheAuthor
AbouttheReviewers
www.PacktPub.com
Supportfiles,eBooks,discountoffers,andmore
WhySubscribe?
FreeAccessforPacktaccountholders
Preface
Whatthisbookcovers
Whatyouneedforthisbook
Whothisbookisfor
Sections
Gettingready
Howtodoit…
Howitworks…
There’smore…
Seealso
Conventions
Readerfeedback
Customersupport
Downloadingtheexamplecode
Errata
Piracy


Questions
1.SettingUpYourEnvironment
Introduction
InstallingVagrantandVirtualBox
Gettingready


Howtodoit…
InstallingVirtualBox
InstallingVagrant
Howitworks…
Seealso
Initializingyourfirstenvironment
Gettingready
Howtodoit…
Howitworks…
InstallingVagrantproviders
Gettingready
Howtodoit…
Howitworks…
Seealso
FindingadditionalVagrantboxes
Gettingready
Howtodoit…
Findingboxes
Initializinganenvironmentwithanewbox:
Addinganewboxwithoutinitializinganenvironment:
There’smore…
UsingexistingvirtualmachineswithVagrant
Gettingready

Howtodoit…
PackagingtheVirtualBoxmachine
ConfiguringaVagrantenvironment
Howitworks…
2.SingleMachineEnvironments
Introduction
DefiningasinglemachineVagrantenvironment
Howtodoit…


SimpleVagrantenvironment
Adefinedsinglemachineenvironment
Howitworks…
ForwardingportsfromaVagrantmachine
Howtodoit…
Howitworks…
StartingaGUIwithVagrant
Gettingready
IntroducingAtlas
Howtodoit…
Howitworks…
There’smore…
SharingVagrantguestfolderswiththehost
Gettingready
Howtodoit…
Howitworks…
Seealso
SharingfoldersusingNetworkFileSystems
Gettingready
Howtodoit…

Howitworks…
There’smore…
Sharingfolderswithrsync
Gettingready
Howtodoit…
Howitworks…
Seealso
Customizingvirtualmachinesettings(VirtualBox)
Gettingready
Howtodoit…
Howitworks…


Customizingvirtualmachinesettings(VMwareDesktop)
Gettingready
Howtodoit…
Howitworks…
Sharingenvironmentswithsourcecontrol
Gettingready
Howtodoit…
Howitworks…
Seealso
3.ProvisioningaVagrantEnvironment
Introduction
Runningbasicshellcommands
Howtodoit…
Howitworks…
ExecutingshellscriptsinaVagrantfile
Gettingready
Howtodoit…

Howitworks…
Shellscriptinginvagrantmachines
Scriptidempotency
Seealso
Provisioningwithexternalshellscripts
Gettingready
Howtodoit…
Howitworks…
Shellprovisioning
Provisioningwithdifferentshelllanguages
Seealso
4.ProvisioningwithConfigurationManagementTools
Introduction
ConfigurationmanagementandVagrantboxes


ConfiguringVagrantenvironmentswithPuppet
Gettingready
Howtodoit…
SettinguptheVagrantenvironment
ConfiguringPuppet
Howitworks…
There’smore…
Seealso
ConfiguringVagrantenvironmentswithChef
Gettingready
Howtodoit…
SettinguptheVagrantenvironment
SettingupChefprovisioning
Howitworks…

There’smore…
ManagingenvironmentswithBerkshelf
ProvisioningwithChefServer
Seealso
ProvisioningVagrantenvironmentswithSalt
Gettingready
Howtodoit…
ConfiguringtheVagrantenvironment
ConfiguringSaltprovisioning
Howitworks…
Seealso
ProvisioningVagrantenvironmentswithAnsible
Gettingready
Howtodoit…
SettinguptheVagrantenvironment
SettingupAnsibleplaybooks
Howitworks…


Seealso
5.NetworkedVagrantEnvironments
Introduction
Creatingalocalnetwork
Gettingready
Howtodoit…
UsingastaticIPaddresswithahostsfile
Howitworks…
There’smore…
Seealso
Definingamultimachineenvironment

Gettingready
Howtodoit…
Howitworks…
Specifyingtheorderofmachineprovisioners
Gettingready
Howtodoit…
Howitworks…
CreatingclustersofVagrantmachines
Gettingready
Howtodoit…
Howitworks…
There’smore…
ConfiguringDNSwithplugins
Configuringaclusterwithetcd
ClusteringwithApacheMesos
Seealso
6.VagrantintheCloud
Introduction
UsingVagrantwithAmazonWebServices
Gettingready


Howtodoit…
CreatingaVagrantIAMaccount
SettingupaVPC
CreatingasecuritykeyforVagrantinstances
InstallingtheVagrant-AWSplugin
Gatheringrequiredinformationfortheprovider
SettinguptheVagrantAWSenvironment
Howitworks…

SavingconfigurationdataoutsidetheVagrantfile
OverridingVagrantfiledefaults
SpecifyingAWSdetails
There’smore…
Seealso
UsingVagrantwithDigitalOcean
Gettingready
CreatingaDigitalOceanAPItoken
CreatinganewSSHkeypair
Howtodoit…
Howitworks…
Seealso
SharinglocalmachineswithHashiCorpAtlas
Gettingready
Howtodoit…
Howitworks…
Seealso
SharingwebapplicationswithHashiCorpAtlas
Gettingready
Howtodoit…
Howitworks…
Seealso
7.PackagingVagrantBoxes


Introduction
PackagingVagrantboxesfromISOfiles
Gettingready
Howtodoit…
Preparingavirtualmachine

PackagingthevirtualmachineasaVagrantbox
InstallingthenewVagrantbox
Howitworks…
There’smore…
Seealso
BuildingVagrantboxeswithPacker
Gettingready
Howtodoit…
Howitworks…
ThebuildingblocksofPackertemplates
BuildingVagrantboxeswithVeeWee
Seealso
SharingVagrantboxes
Gettingready
Howtodoit…
Howitworks…
SharingVagrantboxeswithAtlas
Gettingready
Howtodoit…
There’smore…
Seealso
A.VagrantPlugins
SettingupaRubyruntimeenvironment
Gettingready
Howtodoit…
Howitworks…


Seealso
B.APuppetDevelopmentEnvironment

SettingupaPuppetmasterwiththepuppetapplyprovisioner
Howtodoit…
SettingupasourcecontrolledPuppetmaster
BootstrappingaPuppetmaster
ProvisioningnodeswithaPuppetmaster
There’smore…
Seealso
C.UsingDockerwithVagrant
Introduction
RunningDockercontainerswithVagrant
Howtodoit…
InstallingaDockerimagefromarepository
BuildingaDockerimagewithVagrant
Seealso
Mixedenvironments–theDockerprovisioner
Howtodoit…
Seealso
Index



VagrantVirtualDevelopment
EnvironmentCookbook



VagrantVirtualDevelopment
EnvironmentCookbook
Copyright©2015PacktPublishing
Allrightsreserved.Nopartofthisbookmaybereproduced,storedinaretrievalsystem,

ortransmittedinanyformorbyanymeans,withoutthepriorwrittenpermissionofthe
publisher,exceptinthecaseofbriefquotationsembeddedincriticalarticlesorreviews.
Everyefforthasbeenmadeinthepreparationofthisbooktoensuretheaccuracyofthe
informationpresented.However,theinformationcontainedinthisbookissoldwithout
warranty,eitherexpressorimplied.Neithertheauthor,norPacktPublishing,andits
dealersanddistributorswillbeheldliableforanydamagescausedorallegedtobecaused
directlyorindirectlybythisbook.
PacktPublishinghasendeavoredtoprovidetrademarkinformationaboutallofthe
companiesandproductsmentionedinthisbookbytheappropriateuseofcapitals.
However,PacktPublishingcannotguaranteetheaccuracyofthisinformation.
Firstpublished:February2015
Productionreference:1210215
PublishedbyPacktPublishingLtd.
LiveryPlace
35LiveryStreet
BirminghamB32PB,UK.
ISBN978-1-78439-374-8
www.packtpub.com



Credits
Author
ChadThompson
Reviewers
EmilienKenler
DariusKrištapavičius
MarceloPinheiro
CommissioningEditor
UshaIyer

AcquisitionEditor
RichardBrookes-Bland
ContentDevelopmentEditor
ArwaManasawala
TechnicalEditors
VijinBoricha
HumeraShaikh
CopyEditor
RelinHedly
ProjectCoordinator
DanutaJones
Proofreaders
SimranBhogal
BridgetBraund
Indexer
HemanginiBari
ProductionCoordinator
AparnaBhagat
CoverWork
AparnaBhagat



AbouttheAuthor
ChadThompsonisasoftwaredeveloper,architect,andDevOpsspecialistinCentral
Iowa.Hehas15yearsofexperienceincreatinganddeployingapplicationsfortheWeb.
ChadbeganusingVagrant3yearsagowhenhewastryingtosolveatoughproblemin
legacyapplicationdevelopment.Sincethen,hehasmadeuseofVagrantandconfiguration
managementtoolstosupportthedevelopmentanddeploymentofseveralwebapplications
indatacentersandcloudplatforms.HeholdscertificationsinPuppetandOracle

technologiesandhasenjoyedthepleasureofspeakingbeforeseveraltechnical
conferencesandcamps.Chadholdstwodegreesinphysicsandcanbefoundplayinglow
brassinstrumentsinensemblesaroundthestateofIowa.
ChadhaswrittenarticlesforO’ReillywebpublicationsandtheIOUGSELECTJournal
(wherehebrieflyworkedasanexecutiveeditor).Recently,hereviewedthebookCreating
DevelopmentEnvironmentswithVagrantforPacktPublishing,andrecordedasetofvideo
presentationstitledLearningGitbyInfiniteSkills.
Ioweagreatmeasureofgratitudetomanypeopleforhelpingmewiththeproductionof
thisbook.IwouldliketothankmycolleaguesatDiceHoldingsInc.fortheirsupportand
feedbackduringthedevelopmentofthebook.IwouldliketothankZachArlenof
FullContactinDenver,CO,forintroducingmetoVagrantasasolutiontoaproblemyears
ago.Mostly,Iwouldliketothankmyfamilyfortheircontinuedloveandsupport.
Withthepublicationofthisbook,IwouldalsoliketooffermygratitudetoDr.Robert
MerlinoandthelateDr.NicolaD’AngelooftheUniversityofIowa.Theybothtaughtme
agreatdealaboutformulatingideasandteachingothers,whichIhopeservesthereaders
ofthisbook.



AbouttheReviewers
EmilienKenler,afterworkingonsmallwebprojects,beganfocusingongame
developmentin2008whilehewasinhighschool.Until2011,heworkedfordifferent
groupsandspecializedinsystemadministration.
In2011,hefoundedacompanythatsoldMinecraftserverswhilestudyingcomputer
scienceengineering.EmiliencreatedalightweightIaaS
(basedonnewtechnologies(suchasNode.jsand
RabbitMQ).
Thereafter,heworkedatTaDawebasasystemadministrator,buildingitsinfrastructure
andcreatingtoolstomanagedeploymentsandmonitoring.
In2014,hebegananewadventureatWizcorp,Tokyo.In2014,Emiliengraduatedfrom

theUniversityofTechnologyofCompiègne.
ForPacktPublishing,Emilienhasalsocontributedasarevieweronotherbooks:
LearningNagios4,WojciechKocjan( />MariaDBHighPerformance,PierreMAVRO( />OpenVZEssentials,MarkFurman,( />DariusKrištapavičiusattendedVilniusUniversityandstudiedsoftwareengineeringas
hismajorsubject.In2009,Dariusstartedworkingwithwebapplicationdevelopmentand
sincethen,hegainedconsiderableexperienceandparticularlydevelopedvariousecommercesystems.Whileworkinginthisfield,helearnedthePHPprogramming
languageanddifferentframeworks(suchasCodeIgniterandSymfony2).Atpresent,
DariusisworkingasaprofessionalwebdeveloperandisactivelyengagedinDevOps
method,processautomation,principlesofAgile,andotherassociatedsubjectsofweb
development.
MarceloPinheiroisasoftwareengineerfromPortoAlegre,Brazil.In2000,hestartedto
workasawebdesignerandprogrammerwithASPandPHP.Marceloisstillintouchwith
Microsoft.NETFrameworkandJavatoruntheirrespectivechoiceofdatabasesforweb
applications.Since2003,hehasbeenusingLinux-andUnix-relatedoperationalsystems,
fromSlackwaretoGoboLinux,ArchLinux,CentOS,andDebian.Atpresent,heusesOS
X,andhealsousesFreeBSDtosomeextent.Marcelolostafewnightscompilingand
applyingpatchesontheLinuxkerneltomaketheirdesktopwork.Heisanopensource
enthusiastandactsasaproblemsolver,irrespectiveoftheprogramminglanguage,
database,orplatform.
Afterafewyears,hemovedtoSãoPaulotoworkwithnewertechnologies(suchas
NoSQL,cloudcomputing,andRuby),wherehebegantopresenttechtalkswiththese
technologiesinLocaweb,andRSonRails,thebiggestRubyconferenceinSouthBrazil.


Asanobserver,hecreatedsometoolstostandardizedevelopmentusingtools(suchas
VagrantandRubygems),someoftheseintheirGitHub,inLocawebtoensurefast
applicationpackagingandreducedeploymentrollbacks.In2013,Marceloshiftedhis
careerfocustobecomeafull-stackdeveloperandbegantofollowtheDevOpsmovement.
In2014,heattendedQConSP-InternationalSoftwareDevelopmentConferenceasa
speakerandspokeaboutPackeranditsuseinLocaweb.Currently,Marceloworksasa
DevOpsengineeratMoipPagamentos,whereheisresponsibleforcreatingcontinuous

deploymentsolutions,whichcovernon-PCIorPCIcomplianceenvironments.Heis
currentlyusingGoasapreferableprogramminglanguage.
Helovesplayingtheguitarandspendingtimewithhisbelovedwifeandhiscats,apart
fromtravelinganddrinkingbeer.Hecanbefoundonhisblog(),Twitter
(GitHub(andLinkedin
( />First,Iwanttothankmywifeforherpatience,especiallyondayswhenIcamehomefrom
work,atesomethingquickly,andwentstraighttomyoffice,returningonlytosleep.
Secondly,Iwanttothankmyfriends,whobelievedinmypotentialsincethebeginning
andkeptintouchwithmedespitethedistance,andlastly,mymentorsGleiconMoraes
andRobertoGaiserfortheincentiveandtipsthathelpedmebecomeabettersoftware
engineer.



www.PacktPub.com


×