vagrant入门


introduce:
  https://www.vagrantup.com/intro/index.html

get started
    https://www.vagrantup.com/intro/getting-started/index.html
    $ vagrant init hashicorp/precise64
    $ vagrant up

Project Setup
    https://www.vagrantup.com/intro/getting-started/project_setup.html
    $ mkdir vagrant_getting_started
    $ cd vagrant_getting_started
    $ vagrant init hashicorp/precise64

Boxes
    https://www.vagrantup.com/intro/getting-started/boxes.html
    $ vagrant box add hashicorp/precise64

    Open the Vagrantfile and change the contents to the following
    Vagrant.configure("2") do |config|
      config.vm.box = "hashicorp/precise64"
      config.vm.box_version = "1.1.0"
    end

    Vagrant.configure("2") do |config|
      config.vm.box = "hashicorp/precise64"
      config.vm.box_url = "https://vagrantcloud.com/hashicorp/precise64"
    end

    Discover Vagrant Boxes
    https://vagrantcloud.com/boxes/search


Up And SSH
    https://www.vagrantup.com/intro/getting-started/up.html
    $ vagrant up
    $ vagrant ssh


Synced Folders
    https://www.vagrantup.com/intro/getting-started/synced_folders.html

    By default, Vagrant shares your project directory (remember, that is the one with the Vagrantfile) to the /vagrant directory in your guest machine.

Provisioning
    https://www.vagrantup.com/intro/getting-started/provisioning.html
     Installing Apache
    bootstrap.sh
    #!/usr/bin/env bash

    apt-get update
    apt-get install -y apache2
    if ! [ -L /var/www ]; then
      rm -rf /var/www
      ln -fs /vagrant /var/www
    fi

    Vagrantfile
    Vagrant.configure("2") do |config|
      config.vm.box = "hashicorp/precise64"
      config.vm.provision :shell, path: "bootstrap.sh"
    end

     vagrant up to create your machine and Vagrant will automatically provision it.
     If the guest machine is already running from a previous step, run vagrant reload --provision

     so that you can use your own browser to access the guest machine.

Networking
    https://www.vagrantup.com/intro/getting-started/networking.html
    use Vagrant's networking features to give us additional options for accessing the machine from our host machine.
    Port Forwarding

    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

    Run a vagrant reload or vagrant up (depending on if the machine is already running) so that these changes can take effect.

    Other Networking
    https://www.vagrantup.com/docs/networking/

Share
    https://www.vagrantup.com/intro/getting-started/share.html

Teardown
    https://www.vagrantup.com/intro/getting-started/teardown.html
    vagrant suspend
    vagrant halt
    vagrant destroy




上一篇:什么是Vagrant


下一篇:Vagrant + VirtualBox(一) :安装虚拟机CentOS