gpt4 book ai didi

ubuntu - 默认同步文件夹在 vagrant up 后不起作用,但在 vagrant reload 后起作用

转载 作者:行者123 更新时间:2023-12-04 18:30:32 27 4
gpt4 key购买 nike

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

在设置过程中,我注意到同步文件夹未正确安装在 vagrant up 上。我的意思是,当我尝试从 VM 内部启动 touch /vagrant/foo.txt 时出现权限错误。而且,如果我在主机上的项目目录中创建一个文件,它不会显示在 guest VM 上的 /vagrant 中。

我没有在我的 Vagrantfile 中设置同步文件夹,只是使用默认行为。但是当我 vagrant reload 时,一旦我 SSH 回到虚拟机,同步文件夹就会按预期工作。

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

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

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

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

Vagrant 文件

# -*- 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:~$

最佳答案

我认为是 reboot配置脚本末尾的命令。我在注释掉您的配置脚本步骤时进行了几次测试运行,并且它始终正常工作。如您所述,使用配置脚本会失败。删除 reboot 后最后,共享文件夹安装似乎总是有效。

我发现这篇博文可能更能说明问题:How to Reboot a Vagrant Guest VM During Provisioning .他们描述了重启后重新挂载共享文件夹的需要。

我不确定你甚至需要重新启动。 Cassandra 和 OpsCenter 都不需要它,我认为您的配置设置可以正常工作。

您可以进行的另一个优化是减少 apt-get update 的数量。来电。这些可能会很慢,具体取决于网络连接速度。例如,您可以移动 debian.datastax.com配置步骤到顶部,调用apt-get update一次,然后进行所有安装。

关于ubuntu - 默认同步文件夹在 vagrant up 后不起作用,但在 vagrant reload 后起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25518330/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com