vagrant 1.8.6 安裝過程及總結遇到的坑


下面先總結遇到的問題,這些問題如果你也遇到,可能需要搜索很多次才能找到原因。

如果想看安裝過程,可以先直接跳到后面第二部分部分。

1 問題匯總:

1.1 vagrant版本過高問題。

vagrant 1.8.7版本存在問題。可以搜索:"vagrant 1.8.7 cant download box"

https://github.com/mitchellh/vagrant/issues/6725 也上有人提到。

 1 /opt/vagrant/bin/vagrant -v
 2 Vagrant 1.8.7
 3  4 vagrant box add centos /Users/user/box/src/centos65-x86_64-20140116.box
5 ==> box: Box file was not detected as metadata. Adding it directly... 6 ==> box: Adding box 'centos' (v0) for provider: 7 box: Unpacking necessary files from: file:///Users/user/box/src/centos65-x86_64-20140116.box 8 An error occurred while downloading the remote file. The error 9 message, if any, is reproduced below. Please fix this error and try 10 again.

 

而且后面並沒有列出具體的原因。要查看原因,即使開啟debug。

VAGRANT_LOG=debug vagrant box add --name centos65-x86  /Users/user/box/src/centos65-x86_64-20140116.box --checksum-type sha256 --checksum 84eda9c4f00c86b62509d1007d4f1cf16b86bccb3795659cb56d1ea0007c3adc --provider Virtualbox
​
# ...
DEBUG subprocess: stderr: dyld: Library not loaded: @rpath/libcurl.4.dylib
  Referenced from: /opt/vagrant/embedded/bin/curl
  Reason: Incompatible library version: curl requires version 9.0.0 or later, but libcurl.4.dylib provides version 7.0.0
DEBUG subprocess: Waiting for process to exit. Remaining to timeout: 32000
DEBUG subprocess: Exit status: 5
 WARN downloader: Downloader exit code: 5
ERROR downloader: Exit code: 5
# ...

 

其中部分輸出如上,提示/opt/vagrant/embedded/bin/curl的版本問題:

curl requires version 9.0.0

解決辦法

網上大多提示1.8.7版本確實有如下問題,建議重新安裝1.8.6.

  • 重新安裝Vagrant 1.8.6

  • 使用你系統的curl代替Vagrant curl

sudo ln -nsf /usr/bin/curl /opt/vagrant/embedded/bin/curl

實際上第二步不是必須的。

1.2 vagrant版本過低問題。

vagrant 1.8.1版本存在的問題。這個問題來自與virtulbox的版本配合上面。

 1 /opt/vagrant/bin/vagrant -v
 2 # Vagrant 1.8.1
 3  4 /opt/vagrant/embedded/bin/curl --version
 5 # curl 7.45.0 (x86_64-apple-darwin12.6.0) libcurl/7.45.0 OpenSSL/1.0.2d zlib/1.2.8
 6  7 ls -trl ~/.vagrant.d/boxes/
 8 # blank
 9 10 VAGRANT_LOG=debug vagrant box add --name centos65-x86  /Users/user/box/src/centos65-x86_64-20140116.box
11 # Successfully added box 'centos65-x86' (v0) for 'virtualbox'!
12 13 vagrant box list
14 # centos65-x86 (virtualbox, 0)
15 16 cd /Users/user/box/baseVM/
17 18 vagrant init centos65-x86
19 # A `Vagrantfile` has been placed in this directory. You are now
20 # ready to `vagrant up` your first virtual environment! Please read
21 # the comments in the Vagrantfile as well as documentation on
22 # `vagrantup.com` for more information on using Vagrant.
23 24 vagrant up
25 # ==>  Provider 'virtualbox' not found. We'll automatically install it now...
26 # ==>  Downloading VirtualBox 5.0.10...

 

  從上面可見,1.8.1版本並不能識別到VirtualBox 版本 5.1.10 r112026 (Qt5.6.2)

下面是網上說明;

http://stackoverflow.com/questions/38378418/vagrant-virtualbox-provider-virtualbox-not-found-well-automatically-instal

Vagrant 1.8.4 and older are not compatible with the VirtualBox 5.1.x.
Vagrant 1.8.5 has been released already and it supports the VirtualBox 5.1.x.
 
因此為了配合最新的vb。需要使用vagrant 1.8.5 ~ 1.8.6版本。

1.3 vagrant box下載失敗

默認的下載地址:http://www.vagrantbox.es/

下載不太穩定,下了好多次都中途失敗。提示"失敗 - 已被禁止"。原本是要使用CentOS 6.4 x86_64版本的。結果總下載不了。最后使用了這個版本。

https://github.com/2creatives/vagrant-centos/releases

centos65-x86_64-20140116.box

網頁上該文件的檢驗碼::

SHA256(centos65-x86_64-20140116.box)= 84eda9c4f00c86b62509d1007d4f1cf16b86bccb3795659cb56d1ea0007c3adc

check it:  

1 shasum -a256 centos65-x86_64-20140116.box
2 84eda9c4f00c86b62509d1007d4f1cf16b86bccb3795659cb56d1ea0007c3adc  centos65-x86_64-20140116.box
3 4 md5 centos65-x86_64-20140116.box
5 MD5 (centos65-x86_64-20140116.box) = c6518b158f7babd09dcccc30eb3d9333

為了方便大家下載。我在網盤上放了一個文件,大家可以使用上面的信息自行校驗,我也沒有水平在這個鏡像中裝后門,呵呵。

2 源文件

經過幾輪折騰。確定了各版本。

  • 本機系統:OS X 10.11.3

  • virtualBox: VirtualBox-5.1.10-112026-OSX.dmg

  • vagrant_1.8.6.dmg

  • box: centos65-x86_64-20140116.box

3 安裝vb和vagrant

分別手動安裝virtualBox和vagrant。安裝后

vb下載地址:https://www.virtualbox.org/wiki/Downloads

vagrant地址:https://www.vagrantup.com/downloads.html

vagrant歷史版本:https://releases.hashicorp.com/vagrant/ 

vagrant box:  http://www.vagrantbox.es/

 安裝后檢查:

1 /opt/vagrant/bin/vagrant -v
2 # Vagrant 1.8.6
3 4 /opt/vagrant/embedded/bin/curl --version
5 # curl 7.45.0 (x86_64-apple-darwin13.4.0) libcurl/7.45.0 OpenSSL/1.0.2e zlib/1.2.8
6 7 ls -trl ~/.vagrant.d/boxes/
8 # blank

 

 
              
 1 VAGRANT_LOG=debug vagrant box add --name centos65-x86  /Users/user/box/src/centos65-x86_64-20140116.box
 2 # ==> box: Successfully added box 'centos65-x86' (v0) for 'virtualbox'!
 3  4 ls ~/.vagrant.d/boxes/centos65-x86/0/virtualbox/
 5 total 586952
 6 -rw-r--r--  1 user  staff         25 11 28 13:53 metadata.json
 7 -rw-------  1 user  staff      12064 11 28 13:53 box.ovf
 8 -rw-------  1 user  staff      71680 11 28 13:53 box-disk2.vmdk
 9 -rw-------  1 user  staff  300424192 11 28 13:53 box-disk1.vmdk
10 -rw-r--r--  1 user  staff        505 11 28 13:53 Vagrantfile
11 12 vagrant box list
13 # centos65-x86 (virtualbox, 0)
14 15 cd /Users/user/box/baseVM/
16 17 vagrant init centos65-x86
18 #A Vagrantfile has been placed in this directory. You are now
19 #ready to vagrant up your first virtual environment! Please read
20 #the comments in the Vagrantfile as well as documentation on
21 #vagrantup.com for more information on using Vagrant.
22 23 ls -l
24 #total 8
25 #-rw-r--r--  1 user  staff  3024 11 28 14:55 Vagrantfile
 
啟動:
 1 vagrant up
 2 Bringing machine 'default' up with 'virtualbox' provider...
 3 ==> default: Importing base box 'centos65-x86'...
 4 ==> default: Matching MAC address for NAT networking...
 5 ==> default: Setting the name of the VM: baseVM_default_1480320850854_85192
 6 ==> default: Clearing any previously set network interfaces...
 7 ==> default: Preparing network interfaces based on configuration...
 8     default: Adapter 1: nat
 9 ==> default: Forwarding ports...
10     default: 22 (guest) => 2222 (host) (adapter 1)
11 ==> default: Booting VM...
12 ==> default: Waiting for machine to boot. This may take a few minutes...
13     default: SSH address: 127.0.0.1:2222
14     default: SSH username: vagrant
15     default: SSH auth method: private key
16     default:
17     default: Vagrant insecure key detected. Vagrant will automatically replace
18     default: this with a newly generated keypair for better security.
19     default:
20     default: Inserting generated public key within guest...
21     default: Removing insecure key from the guest if it's present...
22     default: Key inserted! Disconnecting and reconnecting using new SSH key...
23 ==> default: Machine booted and ready!
24 ==> default: Checking for guest additions in VM...
25     default: The guest additions on this VM do not match the installed version of
26     default: VirtualBox! In most cases this is fine, but in rare cases it can
27     default: prevent things such as shared folders from working properly. If you see
28     default: shared folder errors, please make sure the guest additions within the
29     default: virtual machine match the version of VirtualBox you have installed on
30     default: your host and reload your VM.
31     default:
32     default: Guest Additions Version: 4.3.6
33     default: VirtualBox Version: 5.1
34 ==> default: Mounting shared folders...
35     default: /vagrant => /Users/user/box/baseVM

檢查進程

1 ps axu | grep -i virtual
2 # ...

從上面可以看到登陸信息:

  • 127.0.0.1:2222

  • default: SSH username: vagrant

  • 用戶名與密碼均是: vagrant

但登陸並不需要輸入用戶名或機器及端口。

登陸:

1 vagrant ssh2 [vagrant@vagrant-centos65 ~]$ pwd
3 /home/vagrant
4 5 ls -l /vagrant/
6 total 4
7 -rw-r--r-- 1 vagrant vagrant 3016 Nov 28 08:13 Vagrantfile

至此成功進入vagrant虛機。

就在寫這篇文章時,發現1.9.0已經出來了。可以試下最新版本了,應該修復了1.8.7的問題。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM