logo资料库

Vagrant:Up.and.Running(2013.5)].Mitchell.Hashimoto.文字版.pdf

第1页 / 共155页
第2页 / 共155页
第3页 / 共155页
第4页 / 共155页
第5页 / 共155页
第6页 / 共155页
第7页 / 共155页
第8页 / 共155页
资料共155页,剩余部分请下载后查看
Copyright
Table of Contents
Foreword
Preface
Conventions Used in This Book
Using Code Examples
Safari® Books Online
How to Contact Us
Acknowledgements
Chapter 1. An Introduction to Vagrant
Why Vagrant?
The Tao of Vagrant
Alternatives to Vagrant
Plain Desktop Virtualization
Containers
Cloud
Setting Up Vagrant
Installing VirtualBox
Installing Vagrant
Common Mistakes
Using Vagrant Without VirtualBox
Help!
Chapter 2. Your First Vagrant Machine
Up and Running
The Vagrantfile
V1 versus V2 Configuration
Boxes
Up
Working with the Vagrant Machine
State of the Vagrant Machine
SSH
Shared Filesystem
Basic Networking
Teardown
What’s Next?
Chapter 3. Provisioning Your Vagrant VM
Why Automated Provisioning?
Supported Provisioners
Manually Setting Up Apache
Automated Provisioner Basics
Shell Scripts
Chef
Puppet
Multiple Provisioners
“No Provision” Mode
In-Depth Provisioner Usage
Shell Scripts
Chef Server
Puppet
What’s Next?
Chapter 4. Networking in Vagrant
Forwarded Ports
Pros and Cons
Basic Usage
Collision Detection and Correction
TCP versus UDP
Host-Only Networking
Pros and Cons
Basic Usage
Guest Operating System Dependency
Bridged Networking
Pros and Cons
Basic Usage
Composing Networking Options
NAT Requirement As the First Network Interface
What’s Next?
Chapter 5. Modeling Multimachine Clusters
Running Multiple Virtual Machines
Controlling Multiple Machines
Communication Between Machines
Host-Only Networks
Bridged Networks
Real Example: MySQL
What’s Next?
Chapter 6. Boxes
Why Boxes?
Box Format
Basic Box Management with Vagrant
Creating New Boxes from an Existing Environment
Creating New Boxes from Scratch
Creating the VirtualBox Machine
Configuring the Operating System
Installing VirtualBox Guest Additions
Additional Software
Minimizing the Final Box Size
Packaging It Up
Setting Vagrantfile Defaults
What’s Next?
Chapter 7. Extending Vagrant with Plug-Ins
Extensible Features
Managing Vagrant Plug-Ins
Plug-In Development Basics
Plug-In Definition
Plug-In Components
Error Handling
Vagrant Internals
A Basic Plug-In Development Environment
Developing a Custom Command
Component
Implementation
Working with the Virtual Machine
Working with Multimachine Environments
Parsing Command-Line Options
Adding New Configuration Options
Component
Implementation
Accessing the Configuration
Configuration Merging
Validation
Adding a Custom Provisioner
Component
Implementation
Provisioner Configuration
Configuring the Machine
Modifying Existing Vagrant Behavior
Component
Implementation
Useful Keys in the Action Environment
Learning More
Other Plug-In Components
Packaging the Plug-In
Appendix A. Vagrant Environmental Variables
VAGRANT_CWD
VAGRANT_HOME
VAGRANT_LOG
VAGRANT_NO_PLUGINS
VAGRANT_VAGRANTFILE
Appendix B. Vagrant Configuration Reference
Appendix C. Troubleshooting and Debugging
IRC
Mailing List/Google Group
Professional Support
Index
About the Author
Vagrant: Up and Running Mitchell Hashimoto
Vagrant: Up and Running by Mitchell Hashimoto Copyright © 2013 Mitchell Hashimoto. All rights reserved. Printed in the United States of America. Published by O’Reilly Media, Inc., 1005 Gravenstein Highway North, Sebastopol, CA 95472. O’Reilly books may be purchased for educational, business, or sales promotional use. Online editions are also available for most titles (http://my.safaribooksonline.com). For more information, contact our corporate/ institutional sales department: 800-998-9938 or corporate@oreilly.com. Editors: Mike Loukides and Courtney Nash Production Editor: Kristen Borg Proofreader: Jasmine Kwityn Indexer: Fred Brown Cover Designer: Randy Comer Interior Designer: David Futato Illustrator: Rebecca Demarest June 2013: First Edition Revision History for the First Edition: 2013-05-28: First release See http://oreilly.com/catalog/errata.csp?isbn=9781449335830 for release details. Nutshell Handbook, the Nutshell Handbook logo, and the O’Reilly logo are registered trademarks of O’Reilly Media, Inc. Vagrant: Up and Running, the image of a blue rock pigeon, and related trade dress are trademarks of O’Reilly Media, Inc. Many of the designations used by manufacturers and sellers to distinguish their products are claimed as trademarks. Where those designations appear in this book, and O’Reilly Media, Inc., was aware of a trade‐ mark claim, the designations have been printed in caps or initial caps. While every precaution has been taken in the preparation of this book, the publisher and author assume no responsibility for errors or omissions, or for damages resulting from the use of the information contained herein. ISBN: 978-1-449-33583-0 [LSI]
Table of Contents Foreword. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . vii Preface. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ix 1. An Introduction to Vagrant. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 Why Vagrant? 2 The Tao of Vagrant 4 Alternatives to Vagrant 5 Plain Desktop Virtualization 5 Containers 5 Cloud 6 Setting Up Vagrant 6 Installing VirtualBox 7 Installing Vagrant 7 Common Mistakes 13 Using Vagrant Without VirtualBox 13 Help! 14 2. Your First Vagrant Machine. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15 Up and Running 15 The Vagrantfile 17 V1 versus V2 Configuration 19 Boxes 20 Up 21 Working with the Vagrant Machine 23 State of the Vagrant Machine 24 SSH 24 Shared Filesystem 25 Basic Networking 26 Teardown 28 iii
What’s Next? 32 3. Provisioning Your Vagrant VM. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35 Why Automated Provisioning? 36 Supported Provisioners 37 Manually Setting Up Apache 38 Automated Provisioner Basics 41 Shell Scripts 42 Chef 43 Puppet 45 Multiple Provisioners 47 “No Provision” Mode 48 In-Depth Provisioner Usage 48 Shell Scripts 48 Chef Server 49 Puppet 50 What’s Next? 53 4. Networking in Vagrant. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55 Forwarded Ports 55 Pros and Cons 56 Basic Usage 56 Collision Detection and Correction 57 TCP versus UDP 57 Host-Only Networking 57 Pros and Cons 58 Basic Usage 58 Guest Operating System Dependency 59 Bridged Networking 59 Pros and Cons 60 Basic Usage 60 Composing Networking Options 62 NAT Requirement As the First Network Interface 63 What’s Next? 63 5. Modeling Multimachine Clusters. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65 Running Multiple Virtual Machines 66 Controlling Multiple Machines 68 Communication Between Machines 69 Host-Only Networks 69 Bridged Networks 70 Real Example: MySQL 70 iv | Table of Contents
What’s Next? 72 6. Boxes. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73 Why Boxes? 73 Box Format 74 Basic Box Management with Vagrant 75 Creating New Boxes from an Existing Environment 76 Creating New Boxes from Scratch 78 Creating the VirtualBox Machine 78 Configuring the Operating System 79 Installing VirtualBox Guest Additions 80 Additional Software 80 Minimizing the Final Box Size 81 Packaging It Up 81 Setting Vagrantfile Defaults 82 What’s Next? 83 7. Extending Vagrant with Plug-Ins. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85 Extensible Features 85 Managing Vagrant Plug-Ins 86 Plug-In Development Basics 87 Plug-In Definition 87 Plug-In Components 89 Error Handling 90 Vagrant Internals 91 A Basic Plug-In Development Environment 91 Developing a Custom Command 94 Component 94 Implementation 95 Working with the Virtual Machine 96 Working with Multimachine Environments 99 Parsing Command-Line Options 100 Adding New Configuration Options 101 Component 101 Implementation 102 Accessing the Configuration 103 Configuration Merging 104 Validation 107 Adding a Custom Provisioner 107 Component 108 Implementation 108 Provisioner Configuration 110 Table of Contents | v
Configuring the Machine 112 Modifying Existing Vagrant Behavior 113 Component 113 Implementation 114 Useful Keys in the Action Environment 116 Learning More 117 Other Plug-In Components 118 Packaging the Plug-In 118 A. Vagrant Environmental Variables. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 121 B. Vagrant Configuration Reference. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 125 C. Troubleshooting and Debugging. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 133 Index. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 135 vi | Table of Contents
分享到:
收藏