本來覺得Vagrant安裝很容易,沒想到整了大半天。網上看到的文章比較舊了,整理一篇新一些的,但願對像我同樣遇到問題的人有所幫助。git
去VB官方網站下載VirtualBox的Windows安裝包。一路Next就OK了。VirtualBox的硬件加速很重要,Windows 7 默認是關閉VT-x(Intel芯片),須要去BIOS裏開啓。網絡
去Vagrant官網下載Windows下的安裝包,一樣是一路Next,安裝完畢後須要重啓,正好藉此機會去BIOS裏查看下是否開啓了虛擬化技術。ssh
有兩個路徑要手動添加:ide
雖然能夠網絡方式安裝Box,可是,天朝的狀況也是知道的,所以,保險起見,下載下來先。下載地址:http://www.vagrantbox.es/網站
下載完畢,假設把鏡像存在d:\boxes下,運行命令:this
vagrant box add trusty64 d:\boxes\trusty-server-cloudimg-amd64-vagrant-disk1.box
其中,trusty64是盒子在vagrant管理的盒子列表中的名字,後面跟的路徑是盒子文件所在的路徑。正常狀況下,能夠看到以下輸出:編碼
==> box: Box file was not detected as metadata. Adding it directly... ==> box: Adding box 'trusty64' (v0) for provider: box: Unpacking necessary files from: file://d:/boxes/trusty-server-cloudi mg-amd64-vagrant-disk1.box box: Progress: 100% (Rate: 19.0M/s, Estimated time remaining: --:--:--) ==> box: Successfully added box 'trusty64' (v0) for 'virtualbox'!
工做區能夠理解爲項目在本機的代碼,Vagrant會將這個代碼掛載到啓動的虛擬機的相應目錄下,這就實現了,在本機編碼,而代碼在虛擬機裏運行的方法,再也不須要ftp或者別的方式去反覆部署代碼。假設工做區是d:\va, 在命令行下切換到這個目錄,而後執行vagrant init trusty64, 其中trusty64就是在上一步建立的盒子名稱,該命令就是使用trusty64盒子初始化當前目錄爲vagrant的工做區。命令執行成功,會輸出以下信息:加密
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.
在當前目錄下,會有一個Vagrantfile文件。.net
萬事具有,能夠運行一個實例了。使用命令 Vagrant up,正常狀況下,會有以下輸出:命令行
D:\va>vagrant up Bringing machine 'default' up with 'virtualbox' provider... ==> default: Importing base box 'trusty64'... ==> default: Matching MAC address for NAT networking... ==> default: Setting the name of the VM: va_default_1456111656613_62745 ==> 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: 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: Remote connection disconnect. Retrying... default: default: Vagrant insecure key detected. Vagrant will automatically replace default: this with a newly generated keypair for better security. default: default: Inserting generated public key within guest... default: Removing insecure key from the guest if it's present... default: Key inserted! Disconnecting and reconnecting using new SSH key... ==> 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.36 default: VirtualBox Version: 5.0 ==> default: Mounting shared folders... default: /vagrant => D:/va
如下幾個命令,用來管理vagrant啓動的虛擬機。
按照上述步驟,應該能一次搞定,若是仍是遇到了問題,請先查看博文:http://my.oschina.net/u/248080/blog/618060
安裝完畢,運行起來後,總不能什麼都不安裝配置吧。勢必須要ssh登錄。用Windows自帶命令行也是能夠的,執行vagrant ssh就能夠了。
若是習慣用putty,那須要先把Vagrant自帶的key給轉化成putty須要的格式:
若是習慣用Secure Shell Client,經過以下步驟添加一個公鑰: