如何在Mac OS X中安装Vagrant
Vagrant本质上是虚拟化平台之上的一层。
使用vagrant,我们可以定义开发环境的所有方面,然后可以将它们用于创建虚拟机。
Vagrant负责创建,管理和销毁开发环境。
流浪者选择的最受欢迎的虚拟化平台是VirtualBox。
在本文中,我们将逐步介绍在Mac OS X上安装Vagrant的步骤(在本示例中,我使用EI Captain 10.11.4)。
在MAC OS X中安装Vagrant非常简单。
这是因为,可以使用正式提供的标准安装程序来安装虚拟化组件和Vagrant 本身。
最适合vagrant 的虚拟化平台是VirtualBox。
它可免费用于Mac操作系统。
Vagrant可以与任何虚拟化平台一起使用。
在Vagrant 1.1之前,Vagrant已紧密集成并与VirtualBox绑定。
如今,Vagrant可以与几乎任何类型的虚拟化层一起使用。
它甚至可以与亚马逊的AWS等公共云提供商合作。
在本教程中,我们将使用VirtualBox提供的虚拟化层。
这是因为VirtualBox是免费的,并且可用于所有操作系统平台(即Mac,Windows,Linux)。
VirtualBox和Vagrant应该分开安装。
如果我们在未安装VirtualBox的情况下安装Vagrant,则Vagrant会显示一个错误,并要求安装VirtualBox。
除了VirtualBox,我们不需要任何其他依赖关系即可在Mac OS X上安装Vagrant。
第一步是在Mac OS X上安装VirtualBox。
VirtualBox是Oracle提供的免费虚拟化软件。
我们可以从下面的链接下载适用于Mac OS X的VirtualBox。
下载VirtualBox
https://www.virtualbox.org/
Vagrant与VirtualBox版本4.0.x,4.1.x,4.2.x,4.3.x和5.0.x兼容。
对于本文,我已经从上面的链接下载了VirtualBox-5.0.20-106931-OSX.dmg。
在Mac上安装VirtualBox类似于安装其他任何dmg文件的方式。
单击dmg文件,它会引导我们完成安装。
步骤1:第一步是简单地双击VirtualBox dmg文件,这将在Mac中打开以下窗口。
步骤3:单击上面显示的继续按钮,将复制VirtualBox所需的系统文件,并完成安装。
下面显示的是屏幕抓取。
由于我们已经完全满足了Vagrant的基本主要依赖性,现在让我们下载并安装Vagrant。
与VirtualBox相似,Vagrant可以从下面的官方URL下载。
下载针对Mac的Vagrant
在本教程中,我下载了名为vagrant_1.8.1.dmg的安装文件。
只需单击下载的dmg文件即可完成安装。
单击流浪者dmg文件后,我们将被带到以下窗口。
现在,单击上面显示的继续按钮,它将启动安装过程。
完成后,将显示以下消息。
现在,MAC中已准备就绪,可以与Vagrant一起使用。
我们可以通过在MAC中打开终端并运行以下命令来进行Vagrant安装。
可以通过在Mac OS X中按COMMAND + T打开终端。
Saraths-MacBook-Pro:~ sarath$vagrant --version Vagrant 1.8.1 Saraths-MacBook-Pro:~ sarath$
我们可以通过使用Vagrant运行第一个虚拟机来进一步确认Vagrant的安装。
下面显示的Vagrant简单命令将在当前目录中下载一个Vagrant文件。
Saraths-MacBook-Pro:vagrant sarath$vagrant init https://cloud-images.ubuntu.com/vagrant/trusty/current/trusty-server-cloudimg-amd64-vagrant-disk1.box 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将使用该文件来启动Ubuntu 14.04虚拟机。
我们可以使用命令vagrant up(在运行上述命令的目录中)启动虚拟机。
Saraths-MacBook-Pro:vagrant sarath$vagrant up Bringing machine 'default' up with 'virtualbox' provider... ==> default: Box 'https://cloud-images.ubuntu.com/vagrant/trusty/current/trusty-server-cloudimg-amd64-vagrant-disk1.box' could not be found. Attempting to find and install... default: Box Provider: virtualbox default: Box Version: >= 0 ==> default: Box file was not detected as metadata. Adding it directly... ==> default: Adding box 'https://cloud-images.ubuntu.com/vagrant/trusty/current/trusty-server-cloudimg-amd64-vagrant-disk1.box' (v0) for provider: virtualbox default: Downloading: https://cloud-images.ubuntu.com/vagrant/trusty/current/trusty-server-cloudimg-amd64-vagrant-disk1.box ==> default: Successfully added box 'https://cloud-images.ubuntu.com/vagrant/trusty/current/trusty-server-cloudimg-amd64-vagrant-disk1.box' (v0) for 'virtualbox'! ==> default: Importing base box 'https://cloud-images.ubuntu.com/vagrant/trusty/current/trusty-server-cloudimg-amd64-vagrant-disk1.box'... ==> default: Matching MAC address for NAT networking... ==> default: Setting the name of the VM: vagrant_default_1463290350482_23545 ==> 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 Jan 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: 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 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.36 default: VirtualBox Version: 5.0 ==> default: Mounting shared folders... default: /vagrant => /Users/sarath/vagrant
现在,我们可以使用以下vagrant命令SSH到新启动的虚拟机。
Saraths-MacBook-Pro:vagrant sarath$vagrant ssh Welcome to Ubuntu 14.04.4 LTS (GNU/Linux 3.13.0-86-generic x86_64) * Documentation: https://help.ubuntu.com/ System information as of Sun Jan 15 05:32:54 UTC 2015 System load: 0.35 Processes: 82 Usage of /: 3.5% of 39.34GB Users logged in: 0 Memory usage: 25% IP address for eth0: 10.0.2.15 Swap usage: 0% Graph this data and manage this system at: https://landscape.canonical.com/ Get cloud support with Ubuntu Advantage Cloud Guest: http://www.ubuntu.com/business/services/cloud 0 packages can be updated. 0 updates are security updates. _____________________________________________________________________ WARNING! Your environment specifies an invalid locale. This can affect your user experience significantly, including the ability to manage packages. You Jan install the locales by running: sudo apt-get install language-pack-UTF-8 or sudo locale-gen UTF-8 To see all available language packs, run: apt-cache search "^language-pack-[a-z][a-z]$" To disable this message for all users, run: sudo touch /var/lib/cloud/instance/locale-check.skip _____________________________________________________________________ vagrant@vagrant-ubuntu-trusty-64:~$
vagrant ssh命令将带我们使用新启动的计算机的shell提示符。