mac 使用 vagrant 部署 linux 环境,配置端口导出,修复目录共享

安装 Vagrant

安装很简单,去官网下载安装 DMG 文件,双击点开安装即可。下载链接:https://www.vagrantup.com/downloads

启动 Centos 8

$ mkdir ~/vagrant/centos8
$ cd ~/vagrant/centos8
$ vagrant init centos/8

配置端口导出和共享目录

vim ~/vagrant/centos8/Vagrantfile

添加配置项:

config.vm.network "forwarded_port", guest: 5671, host: 5671
config.vm.synced_folder "/Users/kun/workspace", "/workspace"

查看《完整配置文件》

启动

$ vagrant up

如果启动报如下错误,请看下一节解决方案:

Vagrant was unable to mount VirtualBox shared folders. This is usually
because the filesystem "vboxsf" is not available. This filesystem is
made available via the VirtualBox Guest Additions and kernel module.
Please verify that these guest additions are properly installed in the
guest. This is not a bug in Vagrant and is usually caused by a faulty
Vagrant box. For context, the command attempted was:

mount -t vboxsf -o uid=1000,gid=1000 workspace /workspace

The error output from the command was:

mount: /workspace: unknown filesystem type 'vboxsf'.

修复共享目录报错

安装虚拟机依赖:

$ vagrant ssh   # 忽视报错,进入虚拟机
$ sudo yum -y install kernel kernel-devel # 安装依赖
$ exit

安装 vagrant 插件:

$ vagrant plugin install vagrant-vbguest
$ vagrant vbguest # 如果报错,先 vagrant reload 一下
$ vagrant reload
$ vagrant ssh

设置 root 密码

进入虚拟机:

$ sudo passwd root

你可能感兴趣的:(vagrant)