使用Vagrant配置本地开发环境

举报
lxw1844912514 发表于 2022/03/27 02:24:37 2022/03/27
【摘要】 从二零一四年开始使用vagrant+VirtualBox搭建linux开发环境,配置简单灵活,后台运行占用内存少,比vmware好用很多,果断弃用vmware转投vagrant的怀抱;无论是个人搭建开发环境还是团队统一开发环境,vagrant是最方便快捷的方式。 问题一: 但是最近在使用的时候遇到一些坑,记录下...

从二零一四年开始使用vagrant+VirtualBox搭建linux开发环境,配置简单灵活,后台运行占用内存少,比vmware好用很多,果断弃用vmware转投vagrant的怀抱;无论是个人搭建开发环境还是团队统一开发环境,vagrant是最方便快捷的方式。

问题一:

但是最近在使用的时候遇到一些坑,记录下来以免下次遇到浪费时间去查找解决;经过是这样的:从家里的agrant打包了一份开发环境到公司的新电脑上,vagrant init {boxname}初始化后使用vagrant up启动虚拟机却一直启动失败,提示如下:


    
  1. D:\webroot\vagrant>vagrant up
  2. Bringing machine 'default' up with 'virtualbox' provider...
  3. ==> default: Clearing any previously set forwarded ports...
  4. ==> default: Clearing any previously set network interfaces...
  5. ==> default: Preparing network interfaces based on configuration...
  6. default: Adapter 1: nat
  7. ==> default: Forwarding ports...
  8. default: 22 => 2222 (adapter 1)
  9. ==> default: Booting VM...
  10. ==> default: Waiting for machine to boot. This may take a few minutes...
  11. default: SSH address: 127.0.0.1:2222
  12. default: SSH username: vagrant
  13. default: SSH auth method: private key
  14. default: Warning: Connection timeout. Retrying...
  15. default: Warning: Connection timeout. Retrying...
  16. default: Warning: Connection timeout. Retrying...
  17. default: Warning: Connection timeout. Retrying...
  18. default: Warning: Connection timeout. Retrying...
  19. default: Warning: Connection timeout. Retrying...
  20. default: Warning: Connection timeout. Retrying...
  21. default: Warning: Connection timeout. Retrying...
  22. default: Warning: Connection timeout. Retrying...
  23. default: Warning: Connection timeout. Retrying...
  24. default: Warning: Connection timeout. Retrying...
  25. default: Warning: Connection timeout. Retrying...
  26. default: Warning: Connection timeout. Retrying...
  27. default: Warning: Connection timeout. Retrying...
  28. default: Warning: Connection timeout. Retrying...
  29. default: Warning: Connection timeout. Retrying...
  30. default: Warning: Connection timeout. Retrying...
  31. default: Warning: Connection timeout. Retrying...
  32. Timed out while waiting for the machine to boot. This means that
  33. Vagrant was unable to communicate with the guest machine within
  34. the configured ("config.vm.boot_timeout" value) time period.
  35. 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.
  36. 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.
  37. If the box appears to be booting properly, you may want to increase the timeout ("config.vm.boot_timeout") value.

通过查找资料,在stackowverflow上有网友也遇到过相同问题并给出解决方案如下:

  • 将Vagrantfile配置文件中vb.gui = true的注释去掉

    
          
    1. config.vm.provider "virtualbox" do |vb|
    2. # # Don't boot with headless mode
    3. vb.gui = true
    4. #
    5. # # Use VBoxManage to customize the VM. For example to change memory:
    6. # vb.customize ["modifyvm", :id, "--memory", "1024"]
    7. end
  • 运行vagrant up 启动 virtualbox 后,GUI会给出提示

    VT-x/AMD-V硬件加速在您的系统中不可用。您的64-位虚拟机将无法检测到 64-位处理器,从而无法启动。
    
         
  • 这是由于在BOIS中没有开启cpu虚拟化支持,重启F2或F10等进入BIOS设置Virtualization为Enable(我的Thinkpad是Security=>Virtualizatio设置为Enable);
  • 电脑重启后,再次vagrant up启动虚拟机还是有一些问题,当时也没有记录下来错误信息,只记得解决方案是使用vagrant destroy将虚拟机从磁盘中删除,然后使用vagrant up命令重新创建。

问题二 (2015.5.7更新)

vagrant启动报错The following SSH command responded with a non-zero exit status.


    
  1. D:\vagrant_web>vagrant up
  2. Bringing machine 'default' up with 'virtualbox' provider...
  3. ==> default: Clearing any previously set forwarded ports...
  4. ==> default: Clearing any previously set network interfaces...
  5. ==> default: Preparing network interfaces based on configuration...
  6. default: Adapter 1: nat
  7. default: Adapter 2: hostonly
  8. ==> default: Forwarding ports...
  9. default: 80 => 8080 (adapter 1)
  10. default: 3000 => 3000 (adapter 1)
  11. default: 22 => 2222 (adapter 1)
  12. ==> default: Booting VM...
  13. ==> default: Waiting for machine to boot. This may take a few minutes...
  14. default: SSH address: 127.0.0.1:2222
  15. default: SSH username: vagrant
  16. default: SSH auth method: private key
  17. default: Warning: Connection timeout. Retrying...
  18. ==> default: Machine booted and ready!
  19. ==> default: Checking for guest additions in VM...
  20. ==> default: Configuring and enabling network interfaces...
  21. The following SSH command responded with a non-zero exit status.
  22. Vagrant assumes that this means the command failed!
  23. ARPCHECK=no /sbin/ifup eth1 2> /dev/null
  24. Stdout from the command:
  25. Device eth1 does not seem to be present, delaying initialization.
  26. Stderr from the command:

解决方案

虽然vagrant up启动报错,但是vagrant ssh还是能登陆虚拟机的,进入虚拟机后,执行如下命令

sudo rm -f /etc/udev/rules.d/70-persistent-net.rules 

   

对, 问题就处在在持久网络设备udev规则(persistent network device udev rules)是被原VM设置好的,再用box生成新VM时,这些rules需要被更新。而这和Vagrantfile里对新VM设置private network的指令发生冲突。删除就好了。

vagrant reload 再次启动就OK。

以上问题完美解决,记录下来,避免忘记!

Vagrant官网 文档齐全.
segment安装使用方法 网友分享的使用说明,简单明了!

文章来源: blog.csdn.net,作者:lxw1844912514,版权归原作者所有,如需转载,请联系作者。

原文链接:blog.csdn.net/lxw1844912514/article/details/100027690

【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@huaweicloud.com
  • 点赞
  • 收藏
  • 关注作者

评论(0

0/1000
抱歉,系统识别当前为高风险访问,暂不支持该操作

全部回复

上滑加载中

设置昵称

在此一键设置昵称,即可参与社区互动!

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。