在Vagrant中装载共享文件夹之前,我可以强制进行资源调配吗?

在Vagrant中装载共享文件夹之前,我可以强制进行资源调配吗?,vagrant,provisioning,vagrantfile,vagrant-provision,Vagrant,Provisioning,Vagrantfile,Vagrant Provision,我有以下vagrant文件: # -*- mode: ruby -*- # vi: set ft=ruby : Vagrant.configure("2") do |config| config.vm.box = "centos/6" config.vm.provision :shell, :path => "bootstrap.sh" config.vm.network :forwarded_port, host: 8080, guest: 80 config.vm.n

我有以下
vagrant文件

# -*- mode: ruby -*-
# vi: set ft=ruby :

Vagrant.configure("2") do |config|
  config.vm.box = "centos/6"
  config.vm.provision :shell, :path => "bootstrap.sh"
  config.vm.network :forwarded_port, host: 8080, guest: 80
  config.vm.network :forwarded_port, host: 3306, guest: 3306
  config.vm.synced_folder "../../applications", "/var/www/html", :owner=>"apache", :group=>"apache"

  config.vm.provider :virtualbox do |vb|
      vb.customize ["modifyvm", :id, "--memory", 2048]
      vb.customize ["modifyvm", :id, "--natdnshostresolver1", "on"]
      vb.customize ["modifyvm", :id, "--natdnsproxy1", "on"]
      vb.name = "appserver"
   end
end
每次运行
vagrant up
(第一次运行
vagrant destroy-f
)时,我都会出现以下错误:

==> default: Mounting shared folders...
    default: /vagrant => E:/Development/vagrant/centos6
    default: /var/www/html => E:/Development/applications/arx
Vagrant was unable to mount VirtualBox shared folders. This is usually
because the filesystem "vboxsf" is not available. This filesystem is
made available via the VirtualBox Guest Additions and kernel module.
Please verify that these guest additions are properly installed in the
guest. This is not a bug in Vagrant and is usually caused by a faulty
Vagrant box. For context, the command attempted was:

id -u apache    
The error output from the command was:    
id: apache: No such user
错误很明显“apache用户不存在”。正如我所看到的,有两种或“三种”方法可以解决这个问题:

  • 通过从
    synced_文件夹中删除
    :owner=>“apache”,:group=>“apache”
    部分。这是一个很大的问题,至少对我来说是这样,因为如果我删除它们,那么文件夹将属于
    vagrant
    ,当apache试图从
    /var/www/html
    读取内容时,这将/可能会导致问题
  • 通过注释行
    config.vm.synced_文件夹
    ,打开盒子以便安装和设置所有内容,然后关闭盒子并重新站起来,不注释行:它可以工作,但仍然是一个丑陋的解决方案
  • 通过强制在装载任何东西之前进行资源调配:理想的解决方案
有人知道这是否可能,如果可能,如何做到?我找不到关于第三种解决方案的任何信息:(如果你有更好的解决方案,欢迎你在这里发布,它可能会对我和其他人有所帮助


我已经找到了,但是没有帮助。

一个可能的解决方案是以流浪用户的身份运行apache

/etc/httpd/conf
中,可以将用户和组值替换为

User vagrant
Group vagrant
因此,您可以继续与vagrant用户共享您的文件夹,httpd将作为vagrant用户运行