037-vagrant啓動(up)後自動同步文件(rsync-auto)

這是堅持技術寫做計劃(含翻譯)的第37篇,定個小目標999,每週最少2篇。node

本文介紹兩種vagrant up後自動同步文件(rsync) 分別基於 sync 和 nfs (若是不設置的話,須要再起一個終端,單獨運行 vagrant rsync-auto )python

python+vagrant+virtualbox系列文章
linux

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 replygit

nfs

經測試,在win10上,須要安裝插件(vagrant-vbguest vagrant-winnfsd)github

vagrant plugin install vagrant-vbguest vagrant-winnfsd
複製代碼

若是報windows

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/
複製代碼

須要設置CAfilebash

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
複製代碼

設置Vagrantfilepost

# ... 忽略無關內容
  config.vm.synced_folder ".", "/vagrant",
     type:"nfs"
  # ... 忽略無關內容
複製代碼

參考資料

相關文章
相關標籤/搜索