在win下安装vagrantbox

在win下快速安装vagrantbox

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

运行-cmd

1
2
3
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下面

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
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工具登录

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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命令:

1
2
3
4
5
6
7
8
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共享

1
2
3
4
5
6
7
8
9
10
11
# 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/Tq1Ybb

Comments