Vagrant出现的问题整理

Vagrant出现的问题整理

    在安装和使用vagrant的过程中遇到了不少问题,现在来整理下这些问题以及相应的解决办法。

    1、vagrant安装的插件与版本不一致会导致初始化失败

    

    解决办法:

 1 #vagrant 2.2.7
 2 
 3 #对应插件版本
 4 vagrant-proxyconf (2.0.7, global)
 5 vagrant-scp (0.5.7, global)
 6 vagrant-vbguest (0.23.0, global)
 7 
 8 # 查看插件列表
 9 vagrant plugin list
10 
11 #安装插件
12 
13 vagrant plugin install vagrant-vbguest --plugin-version 0.21
14 vagrant plugin install vagrant-proxyconf --plugin-version 2.0.7
15 vagrant plugin install vagrant-scp --plugin-version 0.5.7
16 
17 # 卸载插件
18 vagrant plugin uninstall vagrant-vbguest
19 vagrant plugin uninstall vagrant-hostmanager
20 
21 
22 #安装挂载插件
23 vagrant plugin install vagrant-vbguest --plugin-version 0.23 --plugin-clean-sources --plugin-source https://rubygems.org
24 
25 
26 #管理插件-重新安装
27 vagrant plugin expunge --reinstall

    2、环境变量path中没有添加powershell的路径导致初始化失败

    

     报错:

     Vagrant failed to initialize at a very early stage:Failed to locate the powershell executable on the available PATH. Please ensure powershell is installed and available on the local PATH, then run the command again.

    大概的意思是:在有效的路径中未能执行PowerShell命令。请检查PowerShell的安装和有效的路径,然后再尝试重新运行这个命令。

     解决办法:

    在环境变量path中添加powershell的路径,例如:C:WindowsSystem32WindowsPowerShellv1.0

    以上未生效,最后:在C:WindowsSystem32WindowsPowerShellv1.0中,双击执行powershell.exe

    

    3、编码问题导致无法使用文件挂载功能

    

    

    

    解决办法:

    在生成的Vagrantfile中添加一行:

    Encoding.default_external = 'UTF-8'

 1 Vagrant.configure(2) do |config|
 2 
 3   config.vm.box = "centos7"
 4   Encoding.default_external = 'UTF-8'
 5 
 6   boxes.each do |opts|
 7       config.vm.define opts[:name] do |config|
 8         config.vm.hostname = opts[:name]
 9         config.vm.provider "vmware_fusion" do |v|
10           v.vmx["memsize"] = opts[:mem]
11           v.vmx["numvcpus"] = opts[:cpu]
12         end
13 
14         config.vm.provider "virtualbox" do |v|
15           v.customize ["modifyvm", :id, "--memory", opts[:mem]]
16           v.customize ["modifyvm", :id, "--cpus", opts[:cpu]]
17         end
18 
19         config.vm.network :private_network, ip: opts[:eth1]
20       end
21   end
22 
23   config.vm.synced_folder "./labs", "/home/vagrant/labs"
24   config.vm.provision "shell", privileged: true, path: "./setup.sh"
25 
26 end

    4、与Hyper-V冲突

    Raw-mode is unavailable courtesy of Hyper-V

    

    这种情况是在windows10上面发生的,原因是Windows 10默认开启hyper-v与virtualbox冲突了。

    解决办法:

    1)关闭Hyper-V 

    控制面板→程序→程序和功能→启用或关闭Windows功能 不勾选 即为关闭,' 确定 ' 后需要重启计算机才会生效

    

    2)查看 Hyper-V 是否 关闭

    cmd命令下执行: bcdedit

    如果还未关闭,则需要下载工具来进行关闭

    5、没有root这个用户组

    

     解决办法:Add docker group

1 vagrant ssh docker-host
2 
3 sudo groupadd docker
4 
5 sudo usermod -aG docker root
6 
7 newgrp - docker

    最后执行

    然后再重新执行:vagrant up或者 vagrant  reload

    

原文地址:https://www.cnblogs.com/hld123/p/15191542.html