在流浪者之后,默认同步文件夹不起作用,但在流浪汉重新加载后也是如此

时间:2014-08-27 03:07:47

标签: ubuntu cassandra vagrant virtualbox

我正在构建一个由Virtualbox管理的虚拟机,打算用作Cassandra / OpsCenter的节点。

在设置过程中,我发现同步文件夹无法正确安装在vagrant up上。通过这个,我的意思是当我尝试从VM内部touch /vagrant/foo.txt启动后,我收到权限错误。而且,如果我在主机上的项目目录中创建了一个文件,它就不会显示在来宾VM上的/vagrant中。

我没有在我的Vagrantfile中设置同步文件夹,仅使用默认行为。但是当我vagrant reload时,一旦我SSH回到VM,同步文件夹突然按预期工作。

vagrant upvagrant reload的日志中没有错误。

在阅读了其他一些SO帖子之后,我同时运行了vagrant up --debugvagrant reload --debug,并取出了我能找到的与mount操作相关的所有输出。

下面粘贴了Vagrantfile,配置代码和选定的日志。知道是什么给了这里吗? TIA。

我正在使用Virtualbox 4.3.12 r93733,Vagrant 1.6.3,Hahsicorp Ubuntu 12.04 64-bit VM,在OSX Mavericks 10.9.4上运行。


Vagrantfile

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

# Vagrantfile API/syntax version. Don't touch unless you know what you're doing!
VAGRANTFILE_API_VERSION = "2"

Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
  config.vm.box = "hashicorp/precise64"
  config.vm.provision :shell, path: "bootstrap.sh"
  config.vm.network :forwarded_port, host: 4568, guest: 80
end

Bootstrap.sh

#!/usr/bin/env bash

apt-get update
apt-get install -y python-software-properties
add-apt-repository -y ppa:webupd8team/java
add-apt-repository -y ppa:cassou/emacs
apt-get update
apt-get -y install curl

# install emacs
echo 'INSTALLING EMACS'
apt-get --yes --force-yes install emacs24 emacs24-el emacs24-common-non-dfsg

# install jvm / oracle jdk
# see: https://www.digitalocean.com/community/tutorials/how-to-install-java-on-ubuntu-with-apt-get
echo 'INSTALLING JAVA'
apt-get -y install default-jre

echo 'INSTALLING ORACLE JDK'
echo debconf shared/accepted-oracle-license-v1-1 select true | sudo debconf-set-selections
echo debconf shared/accepted-oracle-license-v1-1 seen true | sudo debconf-set-selections
apt-get --yes --force-yes install oracle-java7-installer

# install cassandra
echo 'INSTALLING CASSANDRA'
echo "deb http://debian.datastax.com/community stable main" | tee -a /etc/apt/sources.list.d/cassandra.sources.list
curl -L http://debian.datastax.com/debian/repo_key | apt-key add -
apt-get update
apt-get -y install dsc20
service cassandra stop
rm -rf /var/lib/cassandra/data/system/*

# install ops center
echo 'INSTALLING OPS CENTER'
echo "deb http://debian.datastax.com/community stable main" | tee -a /etc/apt/sources.list.d/datastax.community.list
apt-get update
apt-get -y install opscenter
service opscenterd start

# reboot the machine
reboot

提取的日志

INITIAL DEBUG STATEMENTS (starting at line ~2701)
INFO synced_folders: Invoking synced folder enable: virtualbox
 INFO interface: output: Mounting shared folders...
 INFO interface: output: ==> default: Mounting shared folders...
==> default: Mounting shared folders...
 INFO interface: detail: /vagrant => /Users/andrew/projects/tutorials/vagrant_cassandra
 INFO interface: detail:     default: /vagrant => /Users/andrew/projects/tutorials/vagrant_cassandra
    default: /vagrant => /Users/andrew/projects/tutorials/vagrant_cassandra
...line 2997
DEBUG guest: Searching for cap: mount_virtualbox_shared_folder
DEBUG guest: Checking in: ubuntu
DEBUG guest: Checking in: debian
DEBUG guest: Checking in: linux
DEBUG guest: Found cap: mount_virtualbox_shared_folder in linux
 INFO guest: Execute capability: mount_virtualbox_shared_folder [#<Vagrant::Machine: default (VagrantPlugins::ProviderVirtualBox::Provider)>, "vagrant", "/vagrant", {:guestpath=>"/vagrant", :hostpath=>"/Users/andrew/projects/tutorials/vagrant_cassandra", :disabled=>false, :owner=>"vagrant", :group=>"vagrant"}] (ubuntu)
DEBUG ssh: Checking whether SSH is ready...
DEBUG ssh: Re-using SSH connection.
 INFO ssh: SSH is ready!
DEBUG ssh: Re-using SSH connection.
 INFO ssh: Execute:  (sudo=false)
DEBUG ssh: Exit status: 0
...line 3026
INFO ssh: Execute: mount -t vboxsf -o uid=`id -u vagrant`,gid=`getent group vagrant | cut -d: -f3` vagrant /vagrant (sudo=true)
DEBUG ssh: stderr: stdin: is not a tty

DEBUG ssh: Exit status: 0
...line 3039
DEBUG ssh: Re-using SSH connection.
 INFO ssh: Execute: /sbin/initctl emit --no-wait vagrant-mounted MOUNTPOINT=/vagrant (sudo=true)
DEBUG ssh: stderr: stdin: is not a tty

DEBUG ssh: Exit status: 0
 INFO warden: Calling OUT action: #<Vagrant::Action::Builtin::SyncedFolders:0x0000010122eeb0>
 INFO warden: Calling OUT action: #<Vagrant::Action::Builtin::SyncedFolderCleanup:0x000001030d91f8>
 INFO warden: Calling OUT action: #<VagrantPlugins::SyncedFolderNFS::ActionCleanup:0x00000103091998>
 INFO warden: Calling OUT action: #<VagrantPlugins::ProviderVirtualBox::Action::PrepareNFSValidIds:0x0000010303e518>
...line
#################
### AT THIS POINT, MY PROJECT ROOT DIR HAS NOT BEEN MOUNTED TO /vagrant, AS IT IS EMPTY
vagrant@precise64:~$ ls /vagrant/

vagrant@precise64:~$

### THEN RAN A RELOAD --DEBUG, WHICH MAKES THE MOUNTED DIRECTORY WORK...
~/projects/tutorials/vagrant_cassandra(master) $ vagrant reload --debug
... line 26309
INFO interface: output: Mounting shared folders...
 INFO interface: output: ==> default: Mounting shared folders...
==> default: Mounting shared folders...
 INFO interface: detail: /vagrant => /Users/andrew/projects/tutorials/vagrant_cassandra
 INFO interface: detail:     default: /vagrant => /Users/andrew/projects/tutorials/vagrant_cassandra
    default: /vagrant => /Users/andrew/projects/tutorials/vagrant_cassandra
...line 26573
DEBUG guest: Searching for cap: mount_virtualbox_shared_folder
DEBUG guest: Checking in: ubuntu
DEBUG guest: Checking in: debian
DEBUG guest: Checking in: linux
DEBUG guest: Found cap: mount_virtualbox_shared_folder in linux
 INFO guest: Execute capability: mount_virtualbox_shared_folder [#<Vagrant::Machine: default (VagrantPlugins::ProviderVirtualBox::Provider)>, "vagrant", "/vagrant", {:guestpath=>"/vagrant", :hostpath=>"/Users/andrew/projects/tutorials/vagrant_cassandra", :disabled=>false, :owner=>"vagrant", :group=>"vagrant"}] (ubuntu)
DEBUG ssh: Checking whether SSH is ready...
DEBUG ssh: Re-using SSH connection.
 INFO ssh: SSH is ready!
DEBUG ssh: Re-using SSH connection.
 INFO ssh: Execute:  (sudo=false)
DEBUG ssh: Exit status: 0
...line 26601
DEBUG ssh: Re-using SSH connection.
 INFO ssh: Execute: mount -t vboxsf -o uid=`id -u vagrant`,gid=`getent group vagrant | cut -d: -f3` vagrant /vagrant (sudo=true)
DEBUG ssh: stderr: stdin: is not a tty
DEBUG ssh: Exit status: 0
...line 26615
DEBUG ssh: Re-using SSH connection.
 INFO ssh: Execute: /sbin/initctl emit --no-wait vagrant-mounted MOUNTPOINT=/vagrant (sudo=true)
DEBUG ssh: stderr: stdin: is not a tty

DEBUG ssh: Exit status: 0
 INFO warden: Calling OUT action: #<Vagrant::Action::Builtin::SyncedFolders:0x000001014f48e8>
 INFO warden: Calling OUT action: #<Vagrant::Action::Builtin::SyncedFolderCleanup:0x0000010142caf0>
 INFO warden: Calling OUT action: #<VagrantPlugins::SyncedFolderNFS::ActionCleanup:0x00000101367430>
 INFO warden: Calling OUT action: #<VagrantPlugins::ProviderVirtualBox::Action::PrepareNFSValidIds:0x000001012c5d60>

### NOW MY PROJECT DIR HAS BEEN SUCCESSFULLY MOUNTED TO /vagrant
vagrant@precise64:~$ ls /vagrant/
bootstrap.sh  Vagrantfile
vagrant@precise64:~$

1 个答案:

答案 0 :(得分:2)

我认为这是配置脚本末尾的reboot命令。我在评论你的配置脚本步骤的同时做了几次测试,它总是正常工作。使用配置脚本,如您所述,它将失败。在最后删除reboot后,共享文件夹安装似乎总是有效。

我发现这篇博文可能会让人更清楚:How to Reboot a Vagrant Guest VM During Provisioning。他们描述了在重新启动后重新安装共享文件夹的必要性。

我不确定你是否需要重启。 Cassandra和OpsCenter都不会要求它,我认为你的配置设置会正常工作。

您可以进行的另一项优化是减少apt-get update次呼叫的数量。根据网络连接速度,这些可能会非常慢。例如,您可以将debian.datastax.com配置步骤移至顶部,拨打apt-get update一次,然后执行所有安装。