037-vagrant启动(up)后自动同步文件(rsync-auto)

2264

这是坚持技术写作计划(含翻译)的第37篇,定个小目标999,每周最少2篇。

本文介绍两种vagrant up后自动同步文件(rsync) 分别基于 sync 和 nfs (如果不设置的话,需要再起一个终端,单独运行 vagrant rsync-auto )

python+vagrant+virtualbox系列文章

sync

  config.vm.synced_folder ".", "/vagrant", type: "rsync",
    # rsync__verbose: true,
    # rsync__auto: true,
    rsync__exclude: ['.git*', 'node_modules*','*.log','*.box','Vagrantfile']

  config.trigger.after :up do |t|
   t.info = "rsync auto"
   t.run = {inline: "vagrant rsync-auto"}
    # 如果想后台运行,则使用下面语句
    # t.run = {inline: "bash -c 'vagrant rsync-auto &'"}
  end

参考 Vagrant Does not Start RSync-Auto on Up or Reload#briancain's reply

nfs

经测试,在win10上,需要安装插件(vagrant-vbguest vagrant-winnfsd)

vagrant plugin install vagrant-vbguest vagrant-winnfsd

如果报

Installing the 'vagrant-vbguest' plugin. This can take a few minutes...
ERROR:  SSL verification error at depth 3: unable to get local issuer certificate (20)
ERROR:  You must add /C=US/O=Starfield Technologies, Inc./OU=Starfield Class 2 Certification Authority to your local trusted store
Vagrant failed to load a configured plugin source. This can be caused
by a variety of issues including: transient connectivity issues, proxy
filtering rejecting access to a configured plugin source, or a configured
plugin source not responding correctly. Please review the error message
below to help resolve the issue:

  SSL_connect returned=1 errno=0 state=error: certificate verify failed (https://gems.hashicorp.com/specs.4.8.gz)

Source: https://gems.hashicorp.com/

需要设置CAfile

set SSL_CERT_FILE="path\to\Vagrant\embedded\cacert.pem"

如果下载速度慢,并且有境外代理服务器,可以考虑设置代理

set http_proxy=http://username:password@ip:port
set https_proxy=http://username:password@ip:port

设置Vagrantfile

  # ... 忽略无关内容
  config.vm.synced_folder ".", "/vagrant",
     type:"nfs"
  # ... 忽略无关内容

参考资料