Mac下使用虚拟机时,通过vagrant+virtualbox的组合是个不错的方案,简便快捷;
(base) zhaoqindeMBP:~ zhaoqin$ vagrant -v
Vagrant 2.2.5
安装完毕,接下来开始体验;
注意:体验之前请再三确认virtualbox已经安装成功,最好是双击图标启动virtualbox,确认能够启动成功;
(base) zhaoqindeMBP:~ zhaoqin$ vagrant box list
There are no installed boxes! Use `vagrant box add` to add some.
base) zhaoqindeMBP:18 zhaoqin$ vagrant init centos/7
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.
(base) zhaoqindeMBP:18 zhaoqin$ vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Box 'centos/7' could not be found. Attempting to find and install...
default: Box Provider: virtualbox
default: Box Version: >= 0
==> default: Loading metadata for box 'centos/7'
default: URL: https://vagrantcloud.com/centos/7
==> default: Adding box 'centos/7' (v1905.1) for provider: virtualbox
default: Downloading: https://vagrantcloud.com/centos/boxes/7/versions/1905.1/providers/virtualbox.box
default: Download redirected to host: cloud.centos.org
==> default: Successfully added box 'centos/7' (v1905.1) for 'virtualbox'!
==> default: Importing base box 'centos/7'...
==> default: Matching MAC address for NAT networking...
==> default: Checking if box 'centos/7' version '1905.1' is up to date...
==> default: Setting the name of the VM: 18_default_1566103400563_66799
==> 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:
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: No guest additions were detected on the base box for this VM! Guest
default: additions are required for forwarded ports, shared folders, host only
default: networking, and more. If SSH fails on this machine, please install
default: the guest additions and repackage the box to continue.
default:
default: This is not an error message; everything may continue to work properly,
default: in which case you may ignore this message.
==> default: Rsyncing folder: /Users/zhaoqin/temp/201908/18/ => /vagrant
vagrant ssh
[vagrant@localhost ~]$ cat /etc/redhat-release
CentOS Linux release 7.6.1810 (Core)
exit
vagrant halt
vagrant up
vagrant reload
vagrant destroy
(base) zhaoqindeMBP:18 zhaoqin$ vagrant ssh
Last login: Sun Aug 18 08:09:43 2019 from 10.0.2.2
[vagrant@localhost ~]$ free -m
total used free shared buff/cache available
Mem: 1838 70 1655 8 112 1624
Swap: 2047 0 2047
至此,Mac下的vagrant安装和体验就完成了,希望本文能给您一些参考,帮助您快速搭建虚拟机环境。