在win下安装vagrantbox

Posted

在win下快速安装vagrantbox

http://rubyinstaller.org/downloads/ 下载并安装Ruby 1.9.3-p374

运行-cmd

C:\Users\Administrator>ruby -v
ruby 1.9.3p374 (2013-01-15) [i386-mingw32]
gem install vagrant-windows

下载并安装 VirtualBox-4.2.4-81684-Win.exe

下载并安装vagrantup下载页面点击这里下载vagrantup

下载lucid32.box并放在D:\vagrant-box下面

D:\>mkdir vagrant-box
D:\>cd vagrant-box
D:\vagrant-box>vagrant box add lucid32 lucid32.box
[vagrant] Downloading with Vagrant::Downloaders::File...
[vagrant] Copying box to temporary location...
[vagrant] Extracting box...
[vagrant] Verifying box...
[vagrant] Cleaning up downloaded box...

D:\vagrant-box>vagrant init lucid32

D:\vagrant-box>vagrant up
[default] Importing base box 'lucid32'...
[default] The guest additions on this VM do not match the install version of
VirtualBox! This may cause things such as forwarded ports, shared
folders, and more to not work properly. If any of those things fail on
this machine, please update the guest additions and repackage the
box.

Guest Additions Version: 4.2.0
VirtualBox Version: 4.2.4
[default] Matching MAC address for NAT networking...
[default] Clearing any previously set forwarded ports...
[default] Forwarding ports...
[default] -- 22 => 2222 (adapter 1)
[default] Creating shared folders metadata...
[default] Clearing any previously set network interfaces...
[default] Booting VM...
[default] Waiting for VM to boot. This can take a few minutes.
[default] VM booted and ready for use!
[default] Mounting shared folders...
[default] -- v-root: /vagrant


D:\vagrant-box>vagrant ssh
`vagrant ssh` isn't available on the Windows platform. You are still able
to SSH into the virtual machine if you get a Windows SSH client (such as
PuTTY). The authentication information is shown below:

Host: 127.0.0.1
Port: 2222
Username: vagrant
Private key: C:/Users/Administrator/.vagrant.d/insecure_private_key
注:如果不用key的话,密码是vagrant

用ssh工具登录

SSH Secure Shell 3.2.9 (Build 283)
Copyright (c) 2000-2003 SSH Communications Security Corp - http://www.ssh.com/

This copy of SSH Secure Shell is a non-commercial version.
This version does not include PKI and PKCS #11 functionality.


Linux lucid32 2.6.32-38-generic #83-Ubuntu SMP Wed Jan 4 11:13:04 UTC 2012 i686 GNU/Linux
Ubuntu 10.04.4 LTS

Welcome to Ubuntu!
 * Documentation:  https://help.ubuntu.com/
New release 'precise' available.
Run 'do-release-upgrade' to upgrade to it.

Welcome to your Vagrant-built virtual machine.
Last login: Fri Sep 14 07:26:29 2012 from 10.0.2.2
vagrant@lucid32:~$ ls
postinstall.sh

常用vagrant命令:

vagrant box add lucid32 lucid32.box #添加box
vagrant inita lucid32 #初始化   
vagrant destroy #注销虚拟机
vagrant up      #启动 
vagrant halt    #停止
vagrant suspend #暂停   
vagrant resume  #恢复
vagrant status  #查看当前虚拟机的状态

设置让win共享目录linux的目录

打开D:\vagrant-box\Vagrantfile

在这个目录下新建一个文件夹vagrant用于与linux共享

# Vagrantfile API/syntax version. Don't touch unless you know what you're doing!
VAGRANTFILE_API_VERSION = "2"

... ...
  # Share an additional folder to the guest VM. The first argument is
  # the path on the host to the actual folder. The second argument is
  # the path on the guest to mount the folder. And the optional third
  # argument is a set of non-required options.
  config.vm.synced_folder "d:\\vagrant-box\\vagrant", "/home/vagrant/data"

... ...

参考:

https://github.com/BIAINC/vagrant-windows

http://www.virtualbox.org/wiki/Downloads

http://www.vagrantbox.es/

http://www.vagrantup.com/


此文章 短链接: http://dlj.bz/TPqhLC