我正在如下面的cmd转储中显示的流浪汉机器中设置同步文件夹,并且期望每当我更新主机上此文件夹中的文件时,更新也将反映在来宾计算机内,但是这不会发生
以下是转储和未发生的证据(我创建了一个示例文件并通过将其中的文本从test1
更改为test2
来修改它):
mypc:~ user$ cd Projects/synctest/
mypc:synctest user$ ls
Vagrantfile
mypc:synctest user$ cat Vagrantfile
# -*- mode: ruby -*-
# vi: set ft=ruby :
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
# always use Vagrants insecure key
config.ssh.insert_key = false
# Setup box
config.vm.box = "coreos-stable"
# Setup shared folder
config.vm.synced_folder ".", "/vagrant"
# Setup memory usage
config.vm.provider "virtualbox" do |v|
v.memory = 2048
end
# Define `dev` vm
config.vm.define :dev do |dev|
end
if Vagrant.has_plugin?("vagrant-cachier")
config.cache.scope = :box
end
end
mypc:synctest user$ echo "test1" > test.txt
mypc:synctest user$ cat test.txt
test1
mypc:synctest user$ vagrant up
Bringing machine 'dev' up with 'virtualbox' provider...
==> dev: Importing base box 'coreos-stable'...
==> dev: Matching MAC address for NAT networking...
==> dev: Checking if box 'coreos-stable' is up to date...
==> dev: Setting the name of the VM: synctest_dev_1429451824339_35638
==> dev: Fixed port collision for 22 => 2222. Now on port 2200.
==> dev: Clearing any previously set network interfaces...
==> dev: Preparing network interfaces based on configuration...
dev: Adapter 1: nat
==> dev: Forwarding ports...
dev: 22 => 2200 (adapter 1)
==> dev: Running 'pre-boot' VM customizations...
==> dev: Booting VM...
==> dev: Waiting for machine to boot. This may take a few minutes...
dev: SSH address: 127.0.0.1:2200
dev: SSH username: core
dev: SSH auth method: private key
dev: Warning: Connection timeout. Retrying...
==> dev: Machine booted and ready!
==> dev: Rsyncing folder: /Users/user/Projects/synctest/ => /vagrant
==> dev: Rsyncing folder: /Users/user/.vagrant.d/cache/coreos-stable/ => /tmp/vagrant-cache
==> dev: Configuring cache buckets...
mypc:synctest user$ vagrant ssh
CoreOS stable (633.1.0)
core@localhost ~ $ cd ../../vagrant/
core@localhost /vagrant $ ls
Vagrantfile test.txt
core@localhost /vagrant $ cat test.txt
test1
core@localhost /vagrant $ exit
logout
Connection to 127.0.0.1 closed.
mypc:synctest user$ cat test.txt
test1
mypc:synctest user$ echo "test2" > test.txt
mypc:synctest user$ cat test.txt
test2
mypc:synctest user$ vagrant ssh
Last login: Sun Apr 19 13:57:37 2015 from 10.0.2.2
CoreOS stable (633.1.0)
core@localhost ~ $ cd ../../vagrant/
core@localhost /vagrant $ ls
Vagrantfile test.txt
core@localhost /vagrant $ cat test.txt
test1
core@localhost /vagrant $ echo "hi from guest machine" > test.txt
core@localhost /vagrant $ cat test.txt
hi from guest machine
core@localhost /vagrant $ exit
logout
Connection to 127.0.0.1 closed.
mypc:synctest user$ cat test.txt
test2
mypc:synctest user$
它甚至应该实时同步吗?如果是,为什么不同步?
修改:OS X 10.8.5
,VirtualBox
,coreos
框。
答案 0 :(得分:33)
在Vagrantfile
同步文件夹类型为默认vboxsf
,但是,在vagrant up stdout中,它显示rsync类型,我认为您需要在配置文件中修复它。
假设您使用的是rsync类型,则应在Vagrantfile
Vagrant.configure("2") do |config|
config.vm.synced_folder ".", "/vagrant", type: "rsync",
rsync__exclude: ".git/"
end
注意:默认情况下,
rsync__auto
设置为true,这意味着rsync-auto
将会观看并自动同步此文件夹。
运行vagrant rsync-auto
,主机和来宾之间的目录应该同步。
有关详细信息,请参阅vagrant docs。