跳转到主要内容
东方龙马 提交于 4 January 2017

在上一节,我们介绍了下载和添加 box,这一节将继续介绍管理 box。

本节内容提要:

  • 1. 创建虚拟机
  • 2. 初始化虚拟机
  • 3. 启动虚拟机
  • 4. 启动虚拟机时遇到的问题及解决方法
    • 4.1 启动超时问题
    • 4.2 在BIOS中开启 VT-x/AMD-V 虚拟化技术支持

1. 创建虚拟机

我们需要先选一个地方用来放置box配置文件的地方。为了方便,我把它放在Vagrant的安装目录下,比如,我的安装目录是:D:\Vagrant。你也可以选择其他目录,这里仅供参考。这里我们依然使用的是Git bash来敲命令。

切换到Vagrant的目录:

cd /d/Vagrant

创建一个“projects”文件夹,用来放置我们的一些虚拟机:

mkdir projects
cd projects

创建一个文件夹,用来放置我们的演示虚拟机配置文件,这里用“centos1”:

mkdir centos1
cd centos1

2. 初始化虚拟机

vagrant box list //先查看一下可用的 Box
vagrant init centos-6.5 //用这个 Box 去初始化一下项目
ls //查看一下当前目录下面的东西

3. 启动虚拟机

vagrant up

稍等一会,虚拟机就可以启动起来了。不过,有些是因为一些配置和电脑硬件问题,还需要进一步来配置解决。 下面我们就继续来看看我所踩过的坑。

4. 启动虚拟机时遇到的问题及解决方法

4.1 启动超时问题

会卡在“default: SSH auth method: private key”这一步很久时间。

稍后提示了这样的错误信息:

Timed out while waiting for the machine to boot. This means that
Vagrant was unable to communicate with the guest machine within
the configured ("config.vm.boot_timeout" value) time period.

通过搜索,发现stackoverflow上有这个问题的解决方法:

http://stackoverflow.com/questions/23293071/timed-out-while-waiting-for-the-machine-to-boot-when-vagrant-up

这个配置在Vagrantfile 里是有的,默认是注释掉了 把这几条前面的“#”去掉,然后执行vagrant reload 重启。

config.vm.provider :virtualbox do |vb|
  vb.gui = true
end

4.2 在BIOS中开启 VT-x/AMD-V 虚拟化技术支持

这时Vritualbox是启动了,但是启动界面弹出如下错误:

VT-x/AMD-V 硬件加速在您的系统中不可用。您的 64-位虚拟机将无法检测到 64-位处理器,从而无法启动;

再次搜索,需要修改Bios的设置。

开启支持虚拟化技术Intel VT技术的:

开机进入BIOS选项 ,依次选Config->CPU->Intel Virtualization Technology,里面有个Intel VT-d Feature ,改成Enabled ,保存退出,关机,然后启动机器。虚拟机的配置,是在:系统->硬件加速,中的 硬件虚拟,记得选上:启用VT-x/AMD-V

联想电脑t440p如何进入bios更改vt?

可以重启下机器,重启过程中连续点击F1进入bios。进入bios后可以到security--Virtualizatio设置下。

相关链接:

设置完成重启,终于可以成功启动虚拟机了。

4. Vagrant常用管理虚拟机的命令

vagrant status    //查看虚拟机的状态

vagrant suspend    //如果是 running ,你就可以使用命令去暂停一下

vagrant resume    //重新恢复启动

vagrant halt    //停止虚拟机的运行

vagrant reload    //重启虚拟机

vagrant up    //当虚拟机关闭时,再次启动

 

Drupal 版本

如果有朋友像我在windows下不是直接用administrator日常使用,而是新建一个隶属于administrators组的管理员用户,那么可能你会遇到我遇到的“permission denied”,这个时候不知道为什么chmod不起作用了,所以回到windows下,右键这个目录属性,安全,然后添加你的管理员允许她全部权限,OK了。

Timed out while waiting for the machine to boot. This means that Vagrant was unable to communicate with the guest machine within the configured ("config.vm.boot_timeout" value) time period. If you look above, you should be able to see the error(s) that Vagrant had when attempting to connect to the machine. These errors are usually good hints as to what may be wrong. If you're using a custom box, make sure that networking is properly working and you're able to connect to the machine. It is a common problem that networking isn't setup properly in these boxes. Verify that authentication configurations are also setup properly, as well. If the box appears to be booting properly, you may want to increase the timeout ("config.vm.boot_timeout") value.