如何为在vagrant

时间:2015-12-23 15:49:41

标签: linux permissions vagrant chef

我尝试使用共享文件夹机制在vagrant中安装数据磁盘,除了默认情况下该目录由vagrant拥有且tomcat6无法使用写信给它。所以我想我可以使用:

在vagrantfile中设置磁盘的所有者
config.vm.synced_folder "data/", "/data", owner: "tomcat6", group: "tomcat6"

但是tomcat6用户还没有存在,因为tomcat配方还没有运行,所以流浪汉失败了:

Failed to mount folders in Linux guest. This is usually because
the "vboxsf" file system is not available. Please verify that
the guest additions are properly installed in the guest and
can work properly. The command attempted was:

mount -t vboxsf -o uid=`id -u tomcat6`,gid=`getent group tomcat6 | cut -d: -f3` data /data
mount -t vboxsf -o uid=`id -u tomcat6`,gid=`id -g tomcat6` data /data

The error output from the last command was:

stdin: is not a tty
id: tomcat6: no such user
id: tomcat6: no such user
uid= requires an argument (i.e. uid==<arg>)

现在我可以通过使用世界写入权限挂载/数据来解决这个问题,但这似乎是错误的&#34;给我(甚至在测试机上)。

那么在我挂载磁盘之前是否有办法让vagrant为我创建一个新用户,或者让Chef稍后为我配置共享磁盘?

4 个答案:

答案 0 :(得分:1)

您可以在挂载共享文件夹时保留所有者vagrant,并在顶部添加一个简短的shell配置程序,使用chown更改所有权。或者,tomcat配方可以自行设置正确的所有权。

答案 1 :(得分:1)

您可以切换到nfs同步提供程序,因为它支持具有未知UID的远程文件。有关详细信息,请参阅https://docs.vagrantup.com/v2/synced-folders/nfs.html

答案 2 :(得分:1)

我用于自己的VM的一种解决方法是强制Vagrant在运行配置后重新运行初始设置:

vagrant up  # this fails at synced_folder; put that at the end of Vagrantfile
vagrant provision  # this creates the user
vagrant halt  # shut down
vagrant up  # re-runs the synced_folder command, this time the user exists

这不是很优雅,但是将其粘贴在bash脚本中,它将支持正常工作的VM。

答案 3 :(得分:0)

如果您知道将来的用户的UID / GID,则只需提供这些值而不是用户/组名即可。例如如果“ tomcat6”的GID / GID为11111,则可以在Vagrantfile中声明:

config.vm.synced_folder "data/", "/data", owner: "11111", group: "11111"
相关问题