简体   繁体   中英

How do I use rsync shared folders in Vagrant on Windows?

I want to develop WordPress websites locally using Vagrant (Host: Windows 8 64-bit; Guest: Ubuntu 12.04 LTS). I am using Chris Wiegman's Primary Vagrant (an Apache version of VVV)

I got it working, but as soon as I added all my files the site ran incredibly slow. After research I'm guessing this is down to shared folders being slow. The work around as mention in this blog post on the Vagrant website , is to use rsync.

Despite their being no instructions on how to get rsync working on Windows, I came across this article which recommends the free version of cwrsync. I also had to add the path environmental variable so that rsync worked across all folders on Windows ( this answer helped with this)

I edited the vagrant file so that rsync would be used by appending ,"rsync", rsync__exclude: ".git/" to the Primary Vagrant vagrant file :

config.vm.synced_folder "sites/stable.wordpress.vagrant", "/var/www/stable.wordpress.vagrant", :owner => "www-data", :mount_options => [ "dmode=775", "fmode=774" ],"rsync", rsync__exclude: ".git/"
config.vm.synced_folder "sites/stable.wordpress.vagrant/uploads", "/var/www/stable.wordpress.vagrant/wordpress/wp-content/uploads", :owner => "www-data", :mount_options => [ "dmode=775", "fmode=774" ],"rsync", rsync__exclude: ".git/"
config.vm.synced_folder "sites/trunk.wordpress.vagrant", "/var/www/trunk.wordpress.vagrant", :owner => "www-data", :mount_options => [ "dmode=775", "fmode=774" ],"rsync", rsync__exclude: ".git/"
config.vm.synced_folder "sites/trunk.wordpress.vagrant/uploads", "/var/www/trunk.wordpress.vagrant/wordpress/wp-content/uploads", :owner => "www-data", :mount_options => [ "dmode=775", "fmode=774" ],"rsync", rsync__exclude: ".git/"
config.vm.synced_folder "sites/Search-Replace-DB", "/var/www/replacedb.vagrant", :owner => "www-data", :mount_options => [ "dmode=775", "fmode=774" ],"rsync", rsync__exclude: ".git/"
config.vm.synced_folder "sites/phpmyadmin", "/var/www/phpmyadmin.vagrant", :owner => "www-data", :mount_options => [ "dmode=775", "fmode=774" ],"rsync", rsync__exclude: ".git/"
config.vm.synced_folder "sites/webgrind", "/var/www/webgrind.vagrant", :owner => "www-data", :mount_options => [ "dmode=775", "fmode=774" ],"rsync", rsync__exclude: ".git/"

Then I did a vagrant up --provision . But unfortunately I am getting the following error messages. Despite trying to find the issue online, I can't.

Here are the error messages:

==> default: Rsyncing folder: /cygdrive/c/Users/IanAnderson/Documents/Sites/Vagrants/Primary-Vagrant/vagrant-local/sites
/stable.wordpress.vagrant/ => /var/www/stable.wordpress.vagrant
==> default:   - Exclude: [".vagrant/", ".git/"]
There was an error when attempting to rsync a synced folder.
Please inspect the error message below for more info.
Host path: /cygdrive/c/Users/IanAnderson/Documents/Sites/Vagrants/Primary-Vagrant/vagrant-local/sites/stable.wordpress.v
agrant/
Guest path: /var/www/stable.wordpress.vagrant
Command: rsync --verbose --archive --delete -z --chmod=ugo=rwX --no-perms -e ssh -p 2222 -o StrictHostKeyChecking=no -i
'C:/Users/IanAnderson/.vagrant.d/insecure_private_key' --exclude .vagrant/ --exclude .git/ /cygdrive/c/Users/IanAnderson
/Documents/Sites/Vagrants/Primary-Vagrant/vagrant-local/sites/stable.wordpress.vagrant/ vagrant@127.0.0.1:/var/www/stabl
e.wordpress.vagrant
Error: Warning: Permanently added '[127.0.0.1]:2222' (RSA) to the list of known hosts.
rsync: connection unexpectedly closed (0 bytes received so far) [Receiver]
rsync error: error in rsync protocol data stream (code 12) at io.c(605) [Receiver=3.0.9]
rsync: read error: Connection reset by peer (104)
rsync error: error in rsync protocol data stream (code 12) at io.c(759) [sender=3.0.6]

Try using MinGW . It brings its own ssh.exe in /bin and rsync.exe in /msys/<version_number>/bin . Adding these directories to my PATH made it work on my machine.

Adding to Sebastian Kliem's answer: for me it was necessary to add the MinGW /bin directory to the start of my PATH. I got the error you mentioned when using git's ssh with MinGW's rsync. Putting MinGW at the start made sure the two worked well together.

This is no rsync solution, but it works for sharing files to a windows host with better performace than regular virtual box shares.

I successfully used this plugin which starts a nfs daemon on windows: https://github.com/winnfsd/vagrant-winnfsd

I haven't tested it thoroughly because it is a work in progress and first time supporting windows on my project. It seems to do the trick and performs decently so far. Haven't tried it with MySQL data shared onto the host, which was the slowest resource of the server stack.

Also, i use it along the vagrant-bindfs plugin to route the user uid/gid. This probably ads overhead to the mix though but automates the whole process.

I know this question is older than the issue, but in case this might help someone: there is a known issue with Vagrant >=1.8.0 and Windows hosts that triggers this kind of error messages.

To prevent this, try removing the following lines (77 to 79) in $VAGRANT_HOME\\embedded\\gems\\gems\\vagrant-1.8.0\\plugins\\synced_folders\\rsync\\helper.rb :

"-o ControlMaster=auto " +
"-o ControlPath=#{controlpath} " +
"-o ControlPersist=10m " +

Source

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM