vagrant 1.8.6 安装过程及总结遇到的坑

时间:2022-07-13 08:37:18

下面先总结遇到的问题,这些问题如果你也遇到,可能需要搜索很多次才能找到原因。

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

1 问题汇总:

1.1 vagrant版本过高问题。

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

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

 /opt/vagrant/bin/vagrant -v
Vagrant 1.8.

vagrant box add centos /Users/user/box/src/centos65-x86_64-.box
==> box: Box file was not detected as metadata. Adding it directly...
==> box: Adding box 'centos' (v0) for provider:
box: Unpacking necessary files from: file:///Users/user/box/src/centos65-x86_64-20140116.box
An error occurred while downloading the remote file. The error
message, if any, is reproduced below. Please fix this error and try
again.

而且后面并没有列出具体的原因。要查看原因,即使开启debug。

VAGRANT_LOG=debug vagrant box add --name centos65-x86  /Users/user/box/src/centos65-x86_64-.box --checksum-type sha256 --checksum 84eda9c4f00c86b62509d1007d4f1cf16b86bccb3795659cb56d1ea0007c3adc --provider Virtualbox

# ...
DEBUG subprocess: stderr: dyld: Library not loaded: @rpath/libcurl..dylib
Referenced from: /opt/vagrant/embedded/bin/curl
Reason: Incompatible library version: curl requires version 9.0. or later, but libcurl..dylib provides version 7.0.
DEBUG subprocess: Waiting for process to exit. Remaining to timeout:
DEBUG subprocess: Exit status:
WARN downloader: Downloader exit code:
ERROR downloader: Exit code:
# ...

其中部分输出如上,提示/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的版本配合上面。

 /opt/vagrant/bin/vagrant -v
# Vagrant 1.8.

/opt/vagrant/embedded/bin/curl --version
# curl 7.45. (x86_64-apple-darwin12.6.0) libcurl/7.45. OpenSSL/1.0.2d zlib/1.2.

ls -trl ~/.vagrant.d/boxes/
# blank

VAGRANT_LOG=debug vagrant box add --name centos65-x86 /Users/user/box/src/centos65-x86_64-.box
# Successfully added box 'centos65-x86' (v0) for 'virtualbox'!

vagrant box list
# centos65-x86 (virtualbox, )

cd /Users/user/box/baseVM/

vagrant init centos65-x86
# 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.

vagrant up
# ==> Provider 'virtualbox' not found. We'll automatically install it now...
# ==> Downloading VirtualBox 5.0....

从上面可见,1.8.1版本并不能识别到VirtualBox 版本 5.1.10 r112026 (Qt5.6.2)

下面是网上说明;

http://*.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:

 shasum -a256 centos65-x86_64-.box
84eda9c4f00c86b62509d1007d4f1cf16b86bccb3795659cb56d1ea0007c3adc centos65-x86_64-.box

md5 centos65-x86_64-.box
MD5 (centos65-x86_64-.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/

安装后检查:

 /opt/vagrant/bin/vagrant -v
# Vagrant 1.8.

/opt/vagrant/embedded/bin/curl --version
# curl 7.45. (x86_64-apple-darwin13.4.0) libcurl/7.45. OpenSSL/1.0.2e zlib/1.2.

ls -trl ~/.vagrant.d/boxes/
# blank

 VAGRANT_LOG=debug vagrant box add --name centos65-x86  /Users/user/box/src/centos65-x86_64-.box
# ==> box: Successfully added box 'centos65-x86' (v0) for 'virtualbox'!

ls ~/.vagrant.d/boxes/centos65-x86//virtualbox/
total
-rw-r--r-- user staff : metadata.json
-rw------- user staff : box.ovf
-rw------- user staff : box-disk2.vmdk
-rw------- user staff : box-disk1.vmdk
-rw-r--r-- user staff : Vagrantfile

vagrant box list
# centos65-x86 (virtualbox, )

cd /Users/user/box/baseVM/

vagrant init centos65-x86
#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.

ls -l
#total
#-rw-r--r-- user staff : Vagrantfile
 
启动:
 vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Importing base box 'centos65-x86'...
==> default: Matching MAC address for NAT networking...
==> default: Setting the name of the VM: baseVM_default_1480320850854_85192
==> default: Clearing any previously set network interfaces...
==> default: Preparing network interfaces based on configuration...
default: Adapter : nat
==> default: Forwarding ports...
default: (guest) => (host) (adapter )
==> default: Booting VM...
==> default: Waiting for machine to boot. This may take a few minutes...
default: SSH address: 127.0.0.1:
default: SSH username: vagrant
default: SSH auth method: private key
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 of
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 the
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.
default: VirtualBox Version: 5.1
==> default: Mounting shared folders...
default: /vagrant => /Users/user/box/baseVM

检查进程

 ps axu | grep -i virtual
# ...

从上面可以看到登陆信息:

  • 127.0.0.1:2222

  • default: SSH username: vagrant

  • 用户名与密码均是: vagrant

但登陆并不需要输入用户名或机器及端口。

登陆:

 vagrant ssh​
[vagrant@vagrant-centos65 ~]$ pwd
/home/vagrant

ls -l /vagrant/
total
-rw-r--r-- vagrant vagrant Nov : Vagrantfile

至此成功进入vagrant虚机。

就在写这篇文章时,发现1.9.0已经出来了。可以试下最新版本了,应该修复了1.8.7的问题。