Vagrant/Virtualbox,文件相关操作较多时共享文件夹不同步 [英] Vagrant / Virtualbox, shared folder out of sync when there are many file-related operation
问题描述
这与 vagrant 或 virtualbox 来宾由于共享文件夹访问缓慢而运行缓慢无关,我们知道可以通过启用 nfs 或多或少地解决这个问题.
This is not about vagrant or virtualbox guest running slowly due to slow shared folder access, we know that can be resolved more or less by enabling nfs.
而是关于当虚拟机中有很多文件操作时,挂载的共享文件夹不同步(启用 nfs 并不能阻止它发生).
It's rather about mounted shared folder go out of sync when there are many file operations within the vm (enable nfs does not prevent it from happening) .
比如我们在安装包的时候,比如在vm里面用phpcomposer
或者node.jsnpm
,有一定概率正常composerupdate
或 npm install
将失败,一旦失败,只有 vagrant reload
将有助于恢复同步文件夹并允许相同的命令毫无问题地通过.
For example, when we are installing packages, like with php composer
or node.js npm
inside the vm, there is a certain probability that normal composer update
or npm install
will fail, and once it failed, only vagrant reload
will help to restore the sync folder and allow the same command to pass without problem.
这种随机失败只发生在共享文件夹(nfs 或非 nfs)上,所以 apt-get upgrade
不会在 vm 文件夹中触发同样的问题.
Such random failure only happens when executing on shared folder (nfs or not), so apt-get upgrade
won't trigger the same problem as it runs within the vm folders.
由于当我们从主机服务器运行 composer 或 npm 时不会出现相同的同步问题,我想知道是什么原因导致的,我们如何调试?
Since the same sync problem does not appear when we run composer or npm from the host server, I am wondering what could have caused it and how do we go about debugging it?
我们的 vagrant 设置和配置:
Our vagrant setup and config:
if Vagrant::Util::Platform.windows?
config.vm.synced_folder "www", "/var/www", :extra => "dmode=777,fmode=777", :owner => "vagrant", :group => "vagrant"
else
config.vm.synced_folder "www", "/var/www", :extra => "dmode=777,fmode=777", :nfs => true
end
来宾:Ubuntu 12.04 LTS x64
Guest: Ubuntu 12.04 LTS x64
主机:Windows 8、Mac OSX 10.8、Ubuntu 13(是的,它们都随机遇到同样的问题)
Host: Windows 8, Mac OSX 10.8, Ubuntu 13 (yes, they all run into the same problem randomly)
推荐答案
觉得我们或多或少已经找到问题的根源了:
Think we have more or less discover the source of problem:
我们的 Ubuntu 12 LTS 盒附带的来宾添加版本 (4.1.x) 与主机上安装的当前 Virtualbox 版本 (4.2.x) 不匹配.所以文件同步失败.
Guest Addition version (4.1.x) that comes with our Ubuntu 12 LTS box does not match current Virtualbox version (4.2.x) installed on host machine. So file sync failed.
简单的修复:
在 vm 中运行此命令
sudo apt-get -y -q purge virtualbox-guest-dkms virtualbox-guest-utils virtualbox-guest-x11
删除旧的访客添加
安装 vagrant vbguest 插件,以便在 up
期间自动处理未来的更新:https://github.com/dotless-de/vagrant-vbguest
install vagrant vbguest plugin so future update is taken care of automatically during up
: https://github.com/dotless-de/vagrant-vbguest
这篇关于Vagrant/Virtualbox,文件相关操作较多时共享文件夹不同步的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!