可以帮你统一团队成员的开发环境。如果你或者你的伙伴创建了一个Vagrantfile,那么你只需要执行vagrant up就行了,所有的软件都会安装并且配置好。团队成员可以通过相同的Vagrantfile来创建他们的开发环境,无论他们是在Linux, Mac OS X, 或者Windows下,这样就可以保证你团队成员的代码是跑在相同的环境中。
安装非常简单,直接下载对应操作系统的版本就可以了
Vagrant 安装后还不能直接使用,因为它只是一个虚拟机管理和配置工具,虚拟机系统的安装和运行还得靠专门的虚拟化软件。Vagrant 默认已经内置了 VirtualBox Provider 用来跟 VirtualBox 交互,所以再去 VirtualBox 官网下载并安装 VirtualBox 就可以正式开始使用了。

程序员搞最多的就是码代码了,可能做很多个项目,公司里搞java的,php的,自己回家再玩个python什么的,想体验下新版本的mongodb或者nginx,Emacs或者vim的配置啦,保不准哪个项目前个版本的数据库是mysql,下个版本用了postgresql, 这么多东西全都搞在一起,装在一个电脑上,肯定会被这各种配置环境搞的晕晕的,烦不胜烦。
怎么办呢,最好是每个项目都有一个干净的开发环境,只为这个项目,可是我们不可能为每一个项目配一个电脑吧,有了,虚拟机,给每一个项目配一个虚拟机,开发A的时候就启A的虚拟机,这样各个开发环境互相独立,干干净净。还有一个问题,我们的项目有多个开发人员,如何保障大家的开发环境都一样呢,总不能每个人都一个个点击鼠标,填写配置参数,建好后上支一个个软件安装吧,这太麻烦了,太不geek了。我们想要的是,环境只配置一遍,然后可以把这个环境打包deliver给别人,别人拿到后,直接启起来就可以用。那有没有这样的东西呢,肯定是有的,Vagrant,它就是用来干这个的。
Create a single file for your project to describe the type of machine you want, the software that needs to be installed, and the way you want to access the machine. Store this file with your project code.
Run a single command — "vagrant up"
SSH into this machine with vagrant ssh
The first step in configuring any Vagrant project is to create aVagrantfile:
  1. Mark the root directory of your project. Many of the configuration options in Vagrant are relative to this root directory.
  2. Describe the kind of machine and resources you need to run your project, as well as what software to install and how you want to access it.

$ mkdir vagrant_getting_started $ cd vagrant_getting_started $ vagrant init
This will place a Vagrantfile in your current directory. 
specifying the box to use for your Vagrant environment is always the first step after creating a new Vagrantfile.
vagrant box add hashicorp/precise64
the username is "hashicorp", and the box is "precise64". 
run vagrant destroy back on your host machine, and Vagrant will terminate the use of any resources by the virtual machine.
The vagrant destroy command does not actually remove the downloaded box file. To completely remove the box file, you can use the vagrant box remove command.
By default, Vagrant shares your project directory (remember, that is the one with the Vagrantfile) to the /vagrant directory in your guest machine.
Note that when you vagrant ssh into your machine, you're in/home/vagrant. /home/vagrant is a different directory from the synced/vagrant directory.
logout退出!
installing packages, users, and more with provisioning:
Let us now serve those files using a webserver.
We could just SSH in and install a webserver and be on our way, but then every person who used Vagrant would have to do the same thing. Instead, Vagrant has built-in support for automated provisioning. Using this feature, Vagrant will automatically install software when youvagrant up so that the guest machine can be repeatably created and ready-to-use.
Vagrant.configure("2") do |config| config.vm.box = "hashicorp/precise64" config.vm.provision :shell, path: "bootstrap.sh" end
The "provision" line is new, and tells Vagrant to use the shellprovisioner to setup the machine, with the bootstrap.sh file. The file path is relative to the location of the project root (where the Vagrantfile is).
If the guest machine is already running from a previous step, run vagrant reload --provision
port forwarding allows you to specify ports on the guest machine to share via a port on the host machine外面的宿主机. This allows you to access a port on your own machine, but actually have all the network traffic forwarded to a specific port on the guest machine.
Vagrant.configure("2") do |config| config.vm.box = "hashicorp/precise64" config.vm.provision :shell, path: "bootstrap.sh" config.vm.network :forwarded_port, guest: 80, host: 4567 end
 load http://127.0.0.1:4567 in your browser. 
分享
Vagrant Share lets you share your Vagrant environment to anyone around the world with an Internet connection. It will give you a URL that will route directly to your Vagrant environment from any device in the world that is connected to the Internet.
Before being able to share your Vagrant environment, you will need an account on HashiCorp's Atlas. Do not worry, it is free.
Once you have an account, log in using vagrant login:
$ vagrant login Username or Email: mitchellh Password (will be hidden): You are now logged in!
SHARE
Once you are logged in, run vagrant share:
$ vagrant share ... ==> default: Your Vagrant Share is running! ==> default: URL: http://frosty-weasel-0857.vagrantshare.com ...
Your URL will be different, so do not try the URL above. Instead, copy the URL that vagrant share outputted for you and visit that in a web browser. It should load the Apache page we setup earlier.
To end the sharing session, hit Ctrl+C in your terminal.
-----------------------------------
停止:
Suspending the virtual machine by calling vagrant suspend will save the current running state of the machine and stop it. When you are ready to begin working again, just run vagrant up, and it will be resumed from where you left off. The main benefit of this method is that it is super fast, usually taking only 5 to 10 seconds to stop and start your work. The downside is that the virtual machine still eats up your disk space, and requires even more disk space to store all the state of the virtual machine RAM on disk.
Halting the virtual machine by calling vagrant halt will gracefully shut down the guest operating system and power down the guest machine. You can use vagrant up when you are ready to boot it again. The benefit of this method is that it will cleanly shut down your machine, preserving the contents of disk, and allowing it to be cleanly started again. The downside is that it'll take some extra time to start from a cold boot, and the guest machine still consumes disk space.
Destroying the virtual machine by calling vagrant destroy will remove all traces 痕迹of the guest machine from your system. It'll stop the guest machine, power it down, and remove all of the guest hard disks. Again, when you are ready to work again, just issue a vagrant up. The benefit of this is that no cruft is left on your machine. The disk space and RAM consumed by the guest machine is reclaimed 回收的and your host machine is left clean. The downside is that vagrant up to get working again will take some extra time since it has to reimport the machine and re-provision it.

vagrant 介绍,安装与使用的更多相关文章

  1. webpack 介绍 & 安装 & 常用命令

    webpack 介绍 & 安装 & 常用命令 webpack系列目录 webpack 系列 一:模块系统的演进 webpack 系列 二:webpack 介绍&安装 webpa ...

  2. [Redis_1] Redis 介绍 && 安装

    0. 说明 Redis 介绍 && 安装 1. Redis 介绍 2. Redis 安装(Windows 10) [2.1 解压 redis-2.2.2-win32-win64.rar ...

  3. 安装Vagrant出错 安装Homestead出错失败

    安装Vagrant出错 安装Homestead出错     我们也可以在电脑上创建其它文件夹,只需保证创建的文件夹路径跟 Homestead.yaml 文件中的 folders - map 保持一致即 ...

  4. Rancher介绍安装以及对docker的管理

    原文:Rancher介绍安装以及对docker的管理 一.简介 Rancher是一个开源的企业级全栈化容器部署及管理平台.Rancher为容器提供一揽子基础架构服务:CNI兼容的网络服务.存储服务.主 ...

  5. MongoDB的介绍安装与基本使用

    MongoDB的介绍安装 关于MongoDB的介绍于安装可参考:https://www.cnblogs.com/DragonFire/p/9135630.html 除了官网下载,可以下载他人下载好分享 ...

  6. vagrant + virtualbox安装centos环境+docker安装

    1. 下载vagrant 并安装,安装完成后,输入vagrant回车查看是否安装成功 2. 下载virtualbox.box并安装,安装完成后. 3. 创建虚拟机文件夹,例如.F:/vmimg/fir ...

  7. 微服务分布式电商项目学习笔记(三)---- docker介绍安装以及使用docker安装软件(2020/7/10)

    其实在介绍docker的使用和安装之前应该还要介绍虚拟机的安装与配置,以及虚拟网络的配置,但是我使用的是vmware,而视频课使用的是vagrant,这一块我简看的,因此没有过多的介绍,至于vmwar ...

  8. Django框架使用一 基本介绍,安装和建项篇

    Django概述 Django 是在快节奏的编辑环境中开发的,设计使得常见 Web 开发任务快速且容易;它可以编写一个数据驱动的Web应用程序,简单的说就是不需要开发者操作数据库. 设计数据模型 尽管 ...

  9. MathType 6.9 介绍安装

    1.介绍 MathType是强大的数学公式编辑器,与常见的文字处理软件和演示程序配合使用,能够在各种文档中加入复杂的数学公式和符号,可用在编辑数学试卷.书籍.报刊.论文.幻灯演示等方面,是编辑数学资料 ...

随机推荐

  1. C++序列化对象

    需求 . 在写代码的过程中,经常会需要把代码层面的对象数据保存到文件,而这些数据会以各种格式存储.例如:json,xml,二进制等等.最近恰好就需要把对象以二进制存储到硬盘.这是一个很简单的需求,相比 ...

  2. LeetCode OJ-- Linked List Cycle II **

    https://oj.leetcode.com/problems/linked-list-cycle-ii/ 判断一个链表中是否有环,如果有,求环的开始位置. 按照上道题目的想法,先判断出是否有环来, ...

  3. MQ 分拆Json数据包然后上传

    public void UploadInsurHistory() { using (IDbConnection connection = ConnConfig.DmsConnection) { IDb ...

  4. UITextView只能显示两行问题

    需求:UITextView只能显示两行 UITextView * textView = [[UITextView alloc]init]; textView.frame = CGRectMake(20 ...

  5. Xamarin XAML语言教程将XAML设计的UI显示到界面

    Xamarin XAML语言教程将XAML设计的UI显示到界面 如果通过XAML将UI设计好以后,就可以将XAML中的内容显示给用户了,也就是显示到界面上.由于创建XAML文件方式的不同,所以将XAM ...

  6. GCJ——Minimum Scalar Product(2008 Round1 AA)

    题意: 给定两组各n个数,可任意调整同一组数之中数字的顺序,求 sum xi*yi i=1..n的最小值. Small: n<=8 abs xy,yi<=1000 Large: n< ...

  7. Java 字符集,编码、解码

    1. 计算机中文件.数据底层都是基于二进制的. 计算机底层并没有文本文件.图片文件之分,它只是记录着每个文件的二进制序列. 字符集:包含着字符和二进制序列之间的对应关系,一个字符对应一个二进制序列. ...

  8. 详解Webpack2的那些路径

    Webpack2 中有很多涉及路径参数配置,若不知其所以然,很容易混淆出错.本文尽可能的汇集了 Webpack2 中设计路径的配置,力争深入浅出. context context 是 webpack ...

  9. 维护一套同时兼容 iOS 6 和 iOS 7,并且能够自动适应两个系统的 UI 风格的代码

    举例:ios6:test.pngios7:ios7_test.png在ios7Image.plist中添加 "test" PS:如果要统一成ios7风格,可以看看UI7Kit yo ...

  10. XCODE 4.5 IOS多语言设置 及NSLocalizedString和NSLocalizedStringFromTable的用法。

    前 些天升级到Xcode4.5,现在正在用Xcode4.5+IOS6开发项目,当使用国际化时,遇到了一点问题,之前版本Xcode上新建 Localizable.strings后,添加语言的“+”号不见 ...