Monday, January 25, 2016

Vagrant / Trellis [Windows Host] - Replace NFS with rsync

If you are using Vagrant under Windows Host, you had the opportunity of witnessing the super slow performance of VirtualBox's default sync folder.

For example, if you are running a nginx/WordPress installation inside your guest VM, you are likely to face various timeouts, errors 504,502 and etc. Your page loading speed could be 10+ seconds.

This can be cured by switching to NFS. You can find details how to switch to NFS in my previous posts. It's just a matter of specifiying :type:"nfs" in your Vagrantfile and reloading the Vagrant vm - vagrant reload.

Unfortunately, if you are looking to run 2+ Vagrant boxes using NFS in Windows 8, you will probably get the "Access denied" error for the second box ( on vagrant up command).

After quite a few tips I've tried, I still haven't succeeded in running 2 boxes with NFS shares in Windows. If you switch one of the VMs to SMB or VirtualBoxes sync folders, you will get it working, but perfomance for that machine will be very poor.

I found another approach which can give your Vagrant Windows-hosted box a great performance boost:
Use the rsync for sync folder sychronization!

-You will probably have to download it as a part of CYGWIN package.

-Also, you will probably have to change the mounting point of environment variable cygdrive in your /etc/fstab located inside the CYGWIN installation directory.

-If you receive "errror in rsync protocol (12)", check this:
https://github.com/mitchellh/vagrant/issues/6702
You will probably have to delete / comment the lines 77-79 in $VAGRANT_HOME\embedded\gems\gems\vagrant-1.8.0\plugins\synced_folders\rsync\helper.rb.

-There are some rumors that you should use Windows console or PoweShell instead of Git Bash for rsync to work (not confirmed, probably due to the version of ssh having precedence in each console)

From my experience, rsync is even faster than NFS, as it relies on the local VMs filesystem. However, make sure you understand that (in the default edition) it's a 1-way protocol (from host -> VM). Also, make sure you use vagrant rsync-auto command to enable live transfers of edited files from host to the Vagrant VM.

This way, you can have 2 Vagrant boxes running blazingly fast at the same time. Hope it helps someone :)


No comments:

Post a Comment

Ubuntu 12.04, 14.04, 16.04 - auto start an app or script before login

To run a command or application at startup, even before the user has logged in, you can use this file: /etc/rc.local The commands entered...