vagrant - 我可以在 Vagrant 中安装共享文件夹之前强制进行配置吗?
问题描述
我有以下内容Vagrantfile
:
# -*- 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 用户不存在”。正如我所看到的,有两种或“三种”方法可以解决此问题:
- 通过
:owner=>"apache", :group=>"apache"
从synced_folder
. 这是一个很大的不,至少对我来说,因为如果我删除它们,那么vagrant
当 apache 尝试从/var/www/html
. - 通过评论该行
config.vm.synced_folder
,启动盒子,以便安装和设置所有内容,然后关闭盒子并再次启动该行:它可以工作,但仍然是一个丑陋的解决方案 - 通过在安装任何东西之前强制进行配置:理想的解决方案。
有谁知道这是否可行,如果可以,怎么办?我无法找到有关第三种解决方案的任何信息 :( 如果您有更好的解决方案,非常欢迎您在这里发帖,它可能会对我和其他人有所帮助。
解决方案
一种可能的解决方案是将 apache 作为 vagrant 用户运行。
在您的/etc/httpd/conf
您可以将用户和组值替换为
User vagrant
Group vagrant
因此您可以继续与 vagrant 用户共享您的文件夹,并且 httpd 将作为 vagrant 用户运行。
推荐阅读
- javascript - 文件不是角度 9 中的构造函数问题
- javascript - 是否可以在 css-in-js 中测试自定义数据属性?
- node.js - 无法在环回 4 中注册 JWT 身份验证策略
- python - Django/Pythons 是消息 - 唯一错误显示字段
- java - 如何在 Firebase 中获取直接父键
- stripe-payments - 我也无法在 magento 1 Stripe Payment Gateway 中向新客户下订单
- scala - Flink scala 案例类
- java - 是否可以替换或修改投影或匿名类的值?
- python - 如何设置 Selenium 节点的浏览器属性?
- nasm - 无法获得正确的 .ascii 和