vagrant box



vagrant下载地址     https://www.vagrantup.com/downloads.html
virtualbox下载地址  https://www.virtualbox.org/


vagrantbox镜像用的项目组提供的


xp@pangxp MINGW64 /e/vagrantBox
$ vagrant --help
Usage: vagrant [options] []


    -v, --version                    Print the version and exit.
    -h, --help                       Print this help.


Common commands:
     box             manages boxes: installation, removal, etc.
     destroy         stops and deletes all traces of the vagrant machine
     global-status   outputs status Vagrant environments for this user
     halt            stops the vagrant machine
     help            shows the help for a subcommand
     init            initializes a new Vagrant environment by creating a Vagrantfile
     login           log in to HashiCorp's Vagrant Cloud
     package         packages a running vagrant environment into a box
     plugin          manages plugins: install, uninstall, update, etc.
     port            displays information about guest port mappings
     powershell      connects to machine via powershell remoting
     provision       provisions the vagrant machine
     push            deploys code in this environment to a configured destination
     rdp             connects to machine via RDP
     reload          restarts vagrant machine, loads new Vagrantfile configuration
     resume          resume a suspended vagrant machine
     snapshot        manages snapshots: saving, restoring, etc.
     ssh             connects to machine via SSH
     ssh-config      outputs OpenSSH valid configuration to connect to the machine
     status          outputs status of the vagrant machine
     suspend         suspends the machine
     up              starts and provisions the vagrant environment
     validate        validates the Vagrantfile
     version         prints current and latest Vagrant version


For help on any individual command run `vagrant COMMAND -h`


Additional subcommands are available, but are either more advanced
or not commonly used. To see all subcommands, run the command
`vagrant list-commands`.


xp@pangxp MINGW64 /e/vagrantBox
$ vagrant box list
There are no installed boxes! Use `vagrant box add` to add some.


xp@pangxp MINGW64 /e/vagrantBox
$ vagrant box add bbc72 http://worker.onex.software/bbc72-dev.box
==> box: Box file was not detected as metadata. Adding it directly...
==> box: Adding box 'bbc72' (v0) for provider:
    box: Downloading: http://worker.onex.software/bbc72-dev.box
    box:
==> box: Successfully added box 'bbc72' (v0) for 'virtualbox'!


xp@pangxp MINGW64 /e/vagrantBox
$ vagrant init bbc72
A `Vagrantfile` has been placed in this directory. You are now
ready to `vagrant up` your first virtual environment! Please read
the comments in the Vagrantfile as well as documentation on
`vagrantup.com` for more information on using Vagrant.


xp@pangxp MINGW64 /e/vagrantBox
$ vagrant up
The version of powershell currently installed on this host is less than
the required minimum version. Please upgrade the installed version of
powershell to the minimum required version and run the command again.


  Installed version: N/A
  Minimum required version: 3


xp@pangxp MINGW64 /e/vagrantBox


#升级了git还不行  改用windows的cmd


E:\vagrantBox>dir
 驱动器 E 中的卷是 新加卷
 卷的序列号是 821D-8439


 E:\vagrantBox 的目录


2018/04/04  11:10              .
2018/04/04  11:10              ..
2018/04/04  11:10              .vagrant
2018/04/04  11:07             3,082 Vagrantfile
               1 个文件          3,082 字节
               3 个目录 22,786,887,680 可用字节


E:\vagrantBox>vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Importing base box 'bbc72'...
==> default: Matching MAC address for NAT networking...
==> default: Setting the name of the VM: vagrantBox_default_1522812360925_96174
Vagrant is currently configured to create VirtualBox synced folders with
the `SharedFoldersEnableSymlinksCreate` option enabled. If the Vagrant
guest is not trusted, you may want to disable this option. For more
information on this option, please refer to the VirtualBox manual:


  https://www.virtualbox.org/manual/ch04.html#sharedfolders


This option can be disabled globally with an environment variable:


  VAGRANT_DISABLE_VBOXSYMLINKCREATE=1


or on a per folder basis within the Vagrantfile:


  config.vm.synced_folder '/host/path', '/guest/path', SharedFoldersEnableSymlin
ksCreate: false
==> default: Clearing any previously set network interfaces...
==> default: Preparing network interfaces based on configuration...
    default: Adapter 1: nat
==> default: Forwarding ports...
    default: 22 (guest) => 2222 (host) (adapter 1)
==> default: Booting VM...
==> default: Waiting for machine to boot. This may take a few minutes...
    default: SSH address: 127.0.0.1:2222
    default: SSH username: vagrant
    default: SSH auth method: private key
    default: Warning: Connection reset. Retrying...
    default: Warning: Connection aborted. Retrying...
    default: Warning: Remote connection disconnect. Retrying...
    default: Warning: Connection aborted. Retrying...
    default: Warning: Remote connection disconnect. Retrying...
    default: Warning: Connection aborted. Retrying...
    default: Warning: Remote connection disconnect. Retrying...
    default: Warning: Connection aborted. Retrying...
    default: Warning: Remote connection disconnect. Retrying...
    default: Warning: Connection aborted. Retrying...
    default: Warning: Remote connection disconnect. Retrying...
    default: Warning: Connection aborted. Retrying...
    default: Warning: Connection reset. Retrying...
    default: Warning: Connection aborted. Retrying...
    default: Warning: Remote connection disconnect. Retrying...
    default: Warning: Connection aborted. Retrying...
==> default: Machine booted and ready!
==> default: Checking for guest additions in VM...
    default: The guest additions on this VM do not match the installed version o
f
    default: VirtualBox! In most cases this is fine, but in rare cases it can
    default: prevent things such as shared folders from working properly. If you
 see
    default: shared folder errors, please make sure the guest additions within t
he
    default: virtual machine match the version of VirtualBox you have installed
on
    default: your host and reload your VM.
    default:
    default: Guest Additions Version: 4.3.28
    default: VirtualBox Version: 5.2
==> default: Mounting shared folders...
    default: /vagrant => E:/vagrantBox


#ssh连接的时候 直接用127.0.0.1:2222既可以  default: SSH address: 127.0.0.1:2222


E:\vagrantBox>vagrant plugin install vagrant-vbguest
Installing the 'vagrant-vbguest' plugin. This can take a few minutes...
Fetching: micromachine-2.0.0.gem (100%)
Fetching: vagrant-vbguest-0.15.1.gem (100%)
Installed the plugin 'vagrant-vbguest (0.15.1)'!


E:\vagrantBox>vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Machine already provisioned. Run `vagrant provision` or use the `--
provision`
==> default: flag to force provisioning. Provisioners marked to run always will
still run.


E:\vagrantBox>vagrant provision


E:\vagrantBox>vagrant halt






xp@pangxp MINGW64 /e/vagrantBox
$ vim Vagrantfile


xp@pangxp MINGW64 /e/vagrantBox
$ vagrant reload
==> default: Attempting graceful shutdown of VM...
==> default: Clearing any previously set forwarded ports...
==> default: Clearing any previously set network interfaces...
==> default: Preparing network interfaces based on configuration...
    default: Adapter 1: nat
==> default: Forwarding ports...
    default: 80 (guest) => 8080 (host) (adapter 1)
    default: 80 (guest) => 8080 (host) (adapter 1)
    default: 22 (guest) => 2222 (host) (adapter 1)
==> default: Running 'pre-boot' VM customizations...
==> default: Booting VM...
==> default: Waiting for machine to boot. This may take a few minutes...
    default: SSH address: 127.0.0.1:2222
    default: SSH username: vagrant
    default: SSH auth method: private key
==> default: Machine booted and ready!
[default] GuestAdditions 5.2.8 running --- OK.
==> default: Checking for guest additions in VM...
==> default: Mounting shared folders...
    default: /vagrant => E:/vagrantBox/data
==> default: Machine already provisioned. Run `vagrant provision` or use the `--provision`
==> default: flag to force provisioning. Provisioners marked to run always will still run.


xp@pangxp MINGW64 /e/vagrantBox
$ vagrant halt
==> default: Attempting graceful shutdown of VM...


vagrant box_第1张图片

比如当前配置 启动后 访问可以使用localhost:8088

绑定host的话可以使用例如 http://b2b2c.test:8088





config.vm.synced_folder   
   "your_folder"(必须)   //物理机目录,可以是绝对地址或相对地址,相对地址是指相对与vagrant配置文件所在目录
  ,"vm_folder(必须)"    // 挂载到虚拟机上的目录地址
  ,create(boolean)--可选     //默认为false,若配置为true,挂载到虚拟机上的目录若不存在则自动创建
  ,disabled(boolean):--可选   //默认为false,若为true,则禁用该项挂载
  ,owner(string):'www'--可选   //虚拟机系统下文件所有者(确保系统下有该用户,否则会报错),默认为vagrant
  ,group(string):'www'--可选   //虚拟机系统下文件所有组( (确保系统下有该用户组,否则会报错),默认为vagrant
  ,mount_options(array):["dmode=775","fmode=664"]--可选  dmode配置目录权限,fmode配置文件权限  //默认权限777
  ,type(string):--可选     //指定文件共享方式,例如:'nfs',vagrant默认根据系统环境选择最佳的文件共享方式








vagrant的命令详解
命令  作用
vagrant box add 添加box的操作
vagrant init    初始化box的操作,会生成vagrant的配置文件Vagrantfile
vagrant up  启动本地环境
vagrant ssh 通过 ssh 登录本地环境所在虚拟机
vagrant halt    关闭本地环境
vagrant suspend 暂停本地环境
vagrant resume  恢复本地环境
vagrant reload  修改了 Vagrantfile 后,使之生效(相当于先 halt,再 up)
vagrant destroy 彻底移除本地环境
vagrant box list    显示当前已经添加的box列表
vagrant box remove  删除相应的box
vagrant package 打包命令,可以把当前的运行的虚拟机环境进行打包
vagrant plugin  用于安装卸载插件
vagrant status  获取当前虚拟机的状态
vagrant global-status   显示当前用户Vagrant的所有环境状态

你可能感兴趣的:(vagrant,box)