使用Vagrant配置本地开发环境「建议收藏」

使用Vagrant配置本地开发环境

大家好,又见面了,我是全栈君。

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

问题一:

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

D:\webroot\vagrant>vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Clearing any previously set forwarded ports...
==> default: Clearing any previously set network interfaces...
==> default: Preparing network interfaces based on configuration...
    default: Adapter 1: nat
==> default: Forwarding ports...
    default: 22 => 2222 (adapter 1)
==> default: Booting VM...
==> default: Waiting for machine to boot. This may take a few minutes...
    default: SSH address: 127.0.0.1:2222
    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...
    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.

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

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

    config.vm.provider "virtualbox" do |vb|
    #   # Don't boot with headless mode
        vb.gui = true
    #
    #   # Use VBoxManage to customize the VM. For example to change     memory:
    #   vb.customize ["modifyvm", :id, "--memory", "1024"]
     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.

D:\vagrant_web>vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Clearing any previously set forwarded ports...
==> default: Clearing any previously set network interfaces...
==> default: Preparing network interfaces based on configuration...
    default: Adapter 1: nat
    default: Adapter 2: hostonly
==> default: Forwarding ports...
    default: 80 => 8080 (adapter 1)
    default: 3000 => 3000 (adapter 1)
    default: 22 => 2222 (adapter 1)
==> default: Booting VM...
==> default: Waiting for machine to boot. This may take a few minutes...
    default: SSH address: 127.0.0.1:2222
    default: SSH username: vagrant
    default: SSH auth method: private key
    default: Warning: Connection timeout. Retrying...
==> default: Machine booted and ready!
==> default: Checking for guest additions in VM...
==> default: Configuring and enabling network interfaces...
The following SSH command responded with a non-zero exit status.
Vagrant assumes that this means the command failed!

ARPCHECK=no /sbin/ifup eth1 2> /dev/null

Stdout from the command:

Device eth1 does not seem to be present, delaying initialization.

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安装使用方法 网友分享的使用说明,简单明了!

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/112245.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • pycharm不支持32位系统怎么办_pycharm不支持32位系统吗

    pycharm不支持32位系统怎么办_pycharm不支持32位系统吗在32位操作系统中安装pycharm过程中发现的一些问题首先是下载了最新版本的pycharm安装后打开,弹出未发现可执行的文件,然后想到了其他的办法1、下载最新版本的pycharm不能直接运行,因此可以下载之前版本的pycharm,这里选择了2017.3版本的window版本下载并安装到自定义的目录,需要注意的是在安装的过程中,有一项需要勾选,添加到桌面32位安装好之后,双…

    2022年8月25日
    7
  • 网站被篡改_网页内容修改

    网站被篡改_网页内容修改   NetCMS的相关新闻显示是根据新闻的Tag来查找所有具有相同的Tag的新闻,然后将其显示的。如,某条新闻的Tag是“工资|奖金”,那么会用下列SQL语句来查找具有相同Tag的新闻:selecttop5*fromahjdcw.NT_NewsWhere[isRecyle]=0And[isLock]=0And[SiteID]=0   And([Tags]L

    2022年9月30日
    4
  • mac系统下mysql开机启动总是3307

    mac系统下mysql开机启动总是3307

    2021年9月9日
    54
  • php curl_init undefined,php运行出现Call to undefined function curl_init()的解决方法

    php curl_init undefined,php运行出现Call to undefined function curl_init()的解决方法在装好PHP后,执行类似$ch=curl_init();这样的语句,出现Calltoundefinedfunctioncurl_init()的错误提示。解决方法如下:1、在php.ini中找到extension=php_curl.dll,去掉前面的,php.ini一般在c:\windows下面。2、在php.ini中找到extension_dir=“ext”,去掉前面的;,改为ex…

    2022年7月13日
    12
  • crontab怎么使用_crontab配置

    crontab怎么使用_crontab配置    使用crontab你可以在指定的时间执行一个shell脚本或者一系列Linux命令。例如系统管理员安排一个备份任务使其每天都运行安装:apt-getinstallcron  (服务器环境下默认都会安装)使用:crontab-e  进入编辑页面(第一次进入会让你选择编辑器)       crontab-l  查看当前的定时任务以上是crontab的使用规则,以及定时方法的…

    2022年8月24日
    7
  • 写给大忙人看的 – Java中上传文件MinIO服务器(2)

    写给大忙人看的 – Java中上传文件MinIO服务器(2)上一篇写给大忙人看的-搭建文件服务器MinIO(一),我们已经成功地搭建了MinIO文件服务器,这一篇讲解在Java中如何上传文件至MinIO一、开发前戏1、项目中引入maven依赖<!–minio相关依赖–><dependency><groupId>io.minio</groupId><artifactId>minio</artifactId><version

    2022年6月1日
    61

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号