相信许多新手和我一样在第一次接触Vagrant的时候,配置环境出现很多问题,我来为大家讲讲如何配置vagrant环境并说一下其中常有的几个问题。
相应软件下载
1.vagrant
vagrant官网
virtual box
virtual box 官网
建议virtual box 不要下载最新的版本,5.1即可,楼主用的5.1.24
3,box 下载
box就是在vagrant中封装好的操作系统
官方box
根据自己的需要下载即可
vagrant 环境配置
1.windows+R ,键入cmd打开命令行窗口
2.键入vagrant box add [list] [box路径]
list 为自己所取的名字,box路径为自己下载的box文件所存储的路径
3.初始化文件 vagrant init [list]
list 为之前取得名字
首先cd 进入到自己想存储的文件夹中
在键入 vagrant init [list],会在该文件夹下生成vagrantfile 文件
3.启动虚拟机 vagrant up
注意一定要在之前的文件夹下打开,
如果成功启动会有提示
注意这里常见的几个问题,
A.错误提示如果有UTF-8字样,即为文件路径下有中文,需要全改为英文,特别注意用户名也为英文,如果用户名为汉字请自行网上百度,有点麻烦,建议新建用户名,注意用户名注销时,用户下的文件会不见,请注意保存,存在其他盘中。
B.如果网络超时
PS D:\工作文件\vagrant\nazf.net_home> vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Importing base box 'centos7.0_nazf'...
==> default: Matching MAC address for NAT networking...
==> default: Setting the name of the VM: nazfnet_home_default_1427381920843_31923
==> default: Fixed port collision for 22 => 2222. Now on port 2200.
==> default: Clearing any previously set network interfaces...
==> default: Preparing network interfaces based on configuration...
default: Adapter 1: nat
==> default: Forwarding ports...
default: 22 => 2200 (adapter 1)
==> default: Booting VM...
==> default: Waiting for machine to boot. This may take a few minutes...
default: SSH address: 127.0.0.1:2200
default: SSH username: vagrant
default: SSH auth method: private key
default: Warning: Connection timeout. Retrying...
default: Warning: Connection timeout. Retrying...
default: Warning: Connection timeout. Retrying...
default: Warning: Connection timeout. Retrying...
default: Warning: Connection timeout. Retrying...
default: Warning: Connection timeout. Retrying...
default: Warning: Connection timeout. Retrying...
default: Warning: Connection timeout. Retrying...
default: Warning: Connection timeout. Retrying...
default: Warning: Connection timeout. Retrying...
default: Warning: Connection timeout. Retrying...
default: Warning: Connection timeout. Retrying...
default: Warning: Connection timeout. Retrying...
default: Warning: Connection timeout. Retrying...
default: Warning: Connection timeout. Retrying...
default: Warning: Connection timeout. Retrying...
default: Warning: Connection timeout. Retrying...
default: Warning: Connection timeout. Retrying...
default: Warning: Connection timeout. Retrying...
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
进入你的BIOS,然后将virtualization(CPU虚拟化)设置为enable即可