vagrant 中的同步文件夹未实时同步 [英] Synced folder in vagrant is not syncing in realtime

查看:22
本文介绍了vagrant 中的同步文件夹未实时同步的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在一个 vagrant 机器中设置一个同步文件夹,如下面的 cmd dump 所示,并期望每当我在主机上更新此文件夹中的文件时,更新也将反映在来宾机器中,但是这不会发生.

这是转储和它没有发生的证据(我创建了一个示例文件并通过将其中的文本从 test1 更改为 test2 来修改它):

mypc:~ user$ cd Projects/synctest/mypc:synctest 用户 $ ls流浪档案mypc:synctest user$ cat Vagrantfile# -*- 模式:红宝石 -*-# vi: 设置 ft=ruby :VAGRANTFILE_API_VERSION = "2"Vagrant.configure(VAGRANTFILE_API_VERSION) 做 |config|# 始终使用 Vagrants 不安全的密钥config.ssh.insert_key = false# 设置框config.vm.box = "coreos-stable"# 设置共享文件夹config.vm.synced_folder ".", "/vagrant"# 设置内存使用config.vm.provider "virtualbox" 做 |v|v. 内存 = 2048结尾# 定义`dev` vmconfig.vm.define :dev 做 |dev|结尾如果 Vagrant.has_plugin?("vagrant-cachier")config.cache.scope = :box结尾结尾mypc:synctest user$ echo "test1" >测试.txtmypc:synctest user$ cat test.txt测试1mypc:synctest user$ vagrant up将机器开发"与虚拟盒"提供程序一起...==>开发:导入基本框'coreos-stable'...==>dev:匹配 NAT 网络的 MAC 地址...==>开发人员:检查coreos-stable"框是否是最新的...==>dev:设置虚拟机名称:synctest_dev_1429451824339_35638==>dev:修复了 22 => 的端口冲突2222. 现在在端口 2200 上.==>开发:清除任何先前设置的网络接口...==>dev:根据配置准备网络接口...开发:适配器 1:nat==>开发:转发端口...开发:22 =>2200(适配器1)==>开发:运行预启动"VM 自定义...==>开发人员:正在启动虚拟机...==>dev:等待机器启动.这可能需要几分钟的时间...开发者:SSH 地址:127.0.0.1:2200开发者:SSH 用户名:核心开发:SSH 身份验证方法:私钥开发:警告:连接超时.正在重试...==>开发人员:机器启动并准备就绪!==>dev:Rsyncing 文件夹:/Users/user/Projects/synctest/=>/流浪汉==>dev:Rsyncing 文件夹:/Users/user/.vagrant.d/cache/coreos-stable/=>/tmp/流浪缓存==>开发:配置缓存桶...mypc:synctest 用户 $ vagrant sshCoreOS 稳定版 (633.1.0)core@localhost ~ $ cd ../../vagrant/核心@本地主机/流浪$ lsVagrantfile test.txtcore@localhost/vagrant $ cat test.txt测试1core@localhost/vagrant $ exit登出与 127.0.0.1 的连接已关闭.mypc:synctest user$ cat test.txt测试1mypc:synctest user$ echo "test2" >测试.txtmypc:synctest user$ cat test.txt测试2mypc:synctest 用户 $ vagrant ssh上次登录时间:2015 年 4 月 19 日星期日 13:57:37 从 10.0.2.2CoreOS 稳定版 (633.1.0)core@localhost ~ $ cd ../../vagrant/核心@本地主机/流浪$ lsVagrantfile test.txtcore@localhost/vagrant $ cat test.txt测试1core@localhost/vagrant $ echo "hi from guest machine" >测试.txtcore@localhost/vagrant $ cat test.txt来自访客机的嗨core@localhost/vagrant $ exit登出与 127.0.0.1 的连接已关闭.mypc:synctest user$ cat test.txt测试2mypc:synctest 用户$

它甚至应该实时同步吗?如果是,为什么不同步?

OS X 10.8.5VirtualBoxcoreos 框.

解决方案

在你的 Vagrantfile 中,同步的文件夹类型是默认的 vboxsf,但是,在 vagrant up stdout 中,它显示 rsync 类型,我认为您需要在配置文件中修复它.

假设您使用的是 rsync 类型,您的 Vagrantfile

中应该包含以下内容

Vagrant.configure("2") do |config|config.vm.synced_folder ".", "/vagrant", type: "rsync",rsync__exclude: ".git/"结尾

<块引用>

注意:默认情况下,rsync__auto 设置为 true,这意味着 rsync-auto 将监视并自动同步此文件夹.

运行 vagrant rsync-auto 并且目录应该在主机和来宾之间同步.

有关详细信息,请参阅 vagrant 文档.

I am setting up a synced folder in a vagrant machine like shown in cmd dump below and expect that whenever I update the files in this folder on the host machine the updates will be reflected inside guest machine too, however this is not happening.

Here is the dump and evidence of it not happening (I create a sample file and modify it by changing text in in it from test1 to 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$

Is it even supposed to sync realtime? If yes, why is not syncing?

Edit: OS X 10.8.5, VirtualBox, coreos box.

解决方案

In your Vagrantfile the synced folder type is default vboxsf, however, in the vagrant up stdout, it is showing rsync type, I think you need to fix it in the config file.

Assume that you are using rsync type, you should have the following in your Vagrantfile

Vagrant.configure("2") do |config|
  config.vm.synced_folder ".", "/vagrant", type: "rsync",
    rsync__exclude: ".git/"
end

NOTE: By default, rsync__auto is set to true, which means rsync-auto will watch and automatically sync this folder.

Run vagrant rsync-auto and the directory should be in sync between host and guest.

Refer to vagrant docs for more information.

这篇关于vagrant 中的同步文件夹未实时同步的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆