基于 macOS 的 Vagrant 部署流程
后知后觉 暂无评论

上一篇文章提到在 CentOS 中进行部署 Vagrant ,为了配合使用因此在 macOS 上安装 Vagrant 。

Vagrant 需要配合虚拟化环境进行工作,因此需要配置依赖环境才能正常工作。

安装 VirtualBox

部署有两种方式,可以使用包管理器 brew 进行部署,也可以下载 dmg 包进行安装。

包管理

需要先安装 brew,然后执行以下命令即可安装。

$ brew cask install virtualbox

若下载速度过慢,可以使用代理工具对终端进行代理,具体不赘述。

$ export https_proxy=http://127.0.0.1:6152;export http_proxy=http://127.0.0.1:6152;export all_proxy=socks5://127.0.0.1:6153

注意!!!

若安装过程中报错

==> installer: The install failed
Error: Command failed to execute!
小贴士:请到 System Preferences (系统偏好设置) -> Security & Privacy (安全与隐私) -> General (普通)中可以看到 Oracle 的被拒绝,点击 Allow (允许)即可。

安装包

官网下载安装包即可,点击中部的 OS X hosts 即可下载。

下载格式为 .DMG ,双击打开安装即可。

注意!!!

若安装过程中报错,提示无法完成安装,请联系开发商。

小贴士:请到 System Preferences (系统偏好设置) -> Security & Privacy (安全与隐私) -> General (普通)中可以看到 Oracle 的被拒绝,点击 Allow (允许)即可。

安装 Vagrant

包管理

$ brew cask install vagrant vagrant-manager

安装包

推荐使用此方式,官网下载选择 macOS 即可自动下载,双击安装即可。

小贴士:注意安装完成后无图标显示,重新打开一个终端输入 vagrant 命令即可测试是否安装成功。

使用流程

添加镜像

$ vagrant box add generic/debian9
小贴士:本文使用 Debian 9 为例,若使用其他发行版请自行搜索替换地址即可。

若出现以下提示为成功

==> box: Loading metadata for box 'generic/debian9'
    box: URL: https://vagrantcloud.com/generic/debian9
This box can work with multiple providers! The providers that it
can work with are listed below. Please review the list and choose
the provider you will be working with.

1) hyperv
2) libvirt
3) parallels
4) virtualbox
5) vmware_desktop

Enter your choice: 4
==> box: Adding box 'generic/debian9' (v1.9.12) for provider: virtualbox
    box: Downloading: https://vagrantcloud.com/generic/boxes/debian9/versions/1.9.12/providers/virtualbox.box
==> box: Box download is resuming from prior download progress
    box: Download redirected to host: vagrantcloud-files-production.s3.amazonaws.com
==> box: Successfully added box 'generic/debian9' (v1.9.12) for 'virtualbox'!

创建并初始化

创建盒子存储目录

$ cd && mkdir Vagrant && cd Vagrant && mkdir debian && cd debian

初始化盒子

$ vagrant init generic/debian9

启动虚拟环境

$ vagrant up
小贴士:必须在初始化目录内执行。
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Importing base box 'generic/debian9'...
==> default: Matching MAC address for NAT networking...
==> default: Checking if box 'generic/debian9' version '1.9.12' is up to date...
==> default: Setting the name of the VM: debian_default_1557394060788_57867
==> 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: Running 'pre-boot' VM customizations...
==> 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: 
    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: 5.2.26
    default: VirtualBox Version: 6.0

即可成功启动沙箱。

具体使用方式请参考相关链接。

附录

相关链接

参考链接

本文撰写于一年前,如出现图片失效或有任何问题,请在下方留言。博主看到后将及时修正,谢谢!
禁用 / 当前已拒绝评论,仅可查看「历史评论」。