【问题标题】:How to improve slow shared folders in vagrant如何改善 vagrant 中缓慢的共享文件夹
【发布时间】:2017-08-03 04:05:51
【问题描述】:

在我的 Windows 7 上,我使用:

  • VirtualBox 5.0.20
  • 流浪者 1.9.1
  • vagrant-share(1.1.6,系统)
  • vagrant-winnfsd (1.3.1)

我有一个带有一些 PHP 软件 (piwik) 的 ubuntu vagrant box,它在特定的 CLI 命令上执行一些涉及文件的处理。我已经测量了命令完成从访客(ubuntu)到主机(win7)的各种类型的共享需要多长时间:

  • 30 秒在一个简单的共享文件夹上。
  • 在 nfs 共享文件夹上 5 秒(通过 config.vm.network "private_network", type: "dhcp"config.vm.synced_folder "piwik", "/web-pub/piwik", :nfs => true, :mount_options => ['actimeo=2'])。
  • 在复制/tmp下的所有相关文件后,不共享0.5秒,未共享。

我在不同的任务上确认成比例相似的数字(例如 drush cc all 在 vanilla drupal 7 安装上)。

你知道如何让共享文件夹的速度超过 5 秒吗?我想避免使用基于 rsync 的解决方案。

【问题讨论】:

标签: ubuntu vagrant filesystems shared-directory vagrant-windows


【解决方案1】:

如果您有数千个文件并且 vagrant 默认挂载主目录,则 Vagrant 文件共享会很慢,因此请尝试禁用默认共享:

config.vm.synced_folder ".", "/vagrant", disabled: true

你可以试试enabling FS Cache。我没有看到启用或未启用有太大区别,但无论如何都保持启用...在来宾中安装 cachefilesd 并将 fsc 添加到安装选项:

config.vm.synced_folder "src/", "/mnt/project", type: "nfs", 
                        mount_options: ['rw', 'vers=3', 'tcp', 'fsc']

你可能会遇到 NFS 的权限问题,你可以使用 bindfs 插件:

config.bindfs.bind_folder "/mnt/project", "/var/www/drupal", 
                          owner: "www-data", group: "www-data"

这是我们用于 drupal8 开发的最终 Vagrantfile

["vagrant-bindfs", "vagrant-vbguest"].each do |plugin|
    unless Vagrant.has_plugin?(plugin)
      raise plugin + ' plugin is not installed. Hint: vagrant plugin install ' + plugin
    end
end

Vagrant.configure("2") do |config|
  config.vm.box = "geerlingguy/ubuntu1604"

  # Shared folders
  config.vm.synced_folder ".", "/vagrant", disabled: true 
  config.vm.synced_folder "src/", "/mnt/drupal", type: "nfs", 
                          mount_options: ['rw', 'vers=3', 'tcp', 'fsc']
  config.bindfs.bind_folder "/mnt/drupal", "/opt/drupal", 
                            owner: "www-data", group: "www-data"

  config.vm.network "private_network", ip: "192.168.33.20"
  config.vm.provider "virtualbox" do |v|
    v.memory = 2048
    v.cpus = 2
  end
end

【讨论】:

  • 感谢您的建议。不幸的是,没有一个能提高性能。
【解决方案2】:

你可以挂载根文件夹“不同步”并挂载其他文件夹“同步”,这是我对 laravel 和 homestead 的配置:

folders:
  - map: "./"
    to: "/home/vagrant/green-rush"
    type: "nfs"
    options:
      disabled: true
  - map: "./app"
    to: "/home/vagrant/green-rush/app"
    type: "nfs"
  - map: "./resources"
    to: "/home/vagrant/green-rush/resources"
    type: "nfs"
  - map: "./routes"
    to: "/home/vagrant/green-rush/routes"
    type: "nfs"
  - map: "./tests"
    to: "/home/vagrant/green-rush/tests"
    type: "nfs"
  - map: "./public"
    to: "/home/vagrant/green-rush/public"
    type: "nfs"

在您的情况下,现在速度应该非常接近 0.5 秒。您可以将所有您想要的文件夹挂载为 “同步文件夹”,只是不要挂载 “.git 文件夹”。,因为最有问题的文件夹是 ” .git" 文件夹。 "node_modules" 文件夹也是非挂载文件夹的好候选者。唯一的问题是现在根文件中的文件现在不同步,但这是一种妥协,您可以使用此命令手动将这些文件移动到 vagrant,例如:

scp "C:\projects\test\.env" "vagrant@vagrant.local:/home/vagrant/test/.env"

或者您可以创建一个脚本,在任何文件更改时自动为您执行此操作。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-03-21
    • 1970-01-01
    • 2017-08-20
    • 2014-06-12
    • 2013-04-05
    • 2016-09-08
    • 1970-01-01
    • 2016-03-28
    相关资源
    最近更新 更多