vagrant常见问题
1.执行vagrant up报错
A Vagrant environment or target machine is required to run this
command. Run `vagrant init` to create a new Vagrant environment. Or,
get an ID of a target machine from `vagrant global-status` to run
this command on. A final option is to change to a directory with a
Vagrantfile and to try again.
少前边vagrant init步骤了,或者没有进入对应vagrant init的文件夹
2. vagrant up时警告Authentication failure. Retrying...
一般看到这个信息时,虚拟机已经启动成功,可以中断后输入命令:vagrant ssh登录,输入密码登录成功
网上说:如果还是失败,需要修改vagrant工作目录下的Vagrantfile文件下添加两行代码:
config.ssh.username = "vagrant"
config.ssh.password = "vagrant"
然后重新加载虚拟机,vagrant ssh登录。我没有碰到这个问题,可以作为参考
3. windows下执行vagrant up报错
The version of powershell currently installed on this host is less than
the required minimum version. Please upgrade the installed version of
powershell to the minimum required version and run the command again.
Installed version: 2
Minimum required version: 3
查了网上资料,说是powershell版本过低,升级版本就可以,参考资料:https://www.cnblogs.com/wenBlog/p/6198354.html
4. vagrant up报错Count’t open file
An error occurred while downloading the remote file. The error message, if any, is reproduced below. Please fix this error and try again.
Count’t open file /Users/senyint/vagrant/test
如果add时指定了box名称,则init时也要指定。命令如下:
$ vagrant box add test package.box
$ vagrant init 应改为:$ vagrant init test
$ vagrant up
5. Vagrant设置ssh端口映射后无法重启(Windows)
在Vagrantfile中设置:
config.vm.network "forwarded_port", guest: 1111, host: 22
config.ssh.port = 1111
config.ssh.guest_port = 22
在mac电脑启动正常,可使用新端口1111访问。但是在Windows电脑下同样配置,无法启动虚拟机。
修改配置文件为:
config.vm.network "forwarded_port", guest: 22, host: 2222, id: "ssh", disabled: "true"
config.vm.network "forwarded_port", guest: 22, host: 1111
注意:第一条规则必须有id: "ssh",否则会报如下错误:
Forwarded port‘2222’ (host port) is declared multiple times with the protocol ‘tcp’
重启后,即可看到转发端口已经更改为1111。