Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I have setup a web server running nginx and another server running php-fpm on Linode VMs. Nginx proxies all PHP requests off to the PHP backend and this works great.

The problem, is that the actual web files need to exists on both the web server and PHP worker and need to be synced.

How is this accomplished? I was thinking an optimal solution would be using shared storage (NFS) and mounting the storage on each server, but I don't have experience with this. Any good guides on this? Is this even possible with Linode?

Also another solution (though not good), would be to run something like rysnc every 3 seconds, but there would be sync lag, and not to mention all that extra network activity.

Thanks for ideas.

share|improve this question
add comment

5 Answers

better than running rsync every three seconds (or something similar) is running rsync whenever files are actually changed. This can be accomplished easily with incron. Incron is like cron, but instead of specifying something like "run this every minute" you can say "run this every time a file changes". You might specify an incrontab like this:

/path/to/webroot IN_MODIFY,IN_CREATE rsync -az $@/$# user@otherserver:$@/$#
/path/to/webroot IN_DELETE rsync --delete $@ user@otherserver:$@
share|improve this answer
    
I can't get this working. Here is the entry in my incrontab (pastie.org/3351422). I try the rsync piece by itself and it works, so the problem is incron. Any ideas? –  Justin Feb 9 '12 at 23:26
    
should the end of that line really be /srv and not /srv/ or /srv/www –  stew Feb 10 '12 at 1:04
add comment

We have a similar setup with nginx in front of ruby app servers. We're using gluster in this scenario. The load-balanced web servers are the gluster servers, with the app servers as the gluster clients.

Gluster uses FUSE, so it might be easier to run in a VPS environment.

share|improve this answer
    
Gluster seems like a great choice. So linode caps our network throughput at 100mbps, is this going to be an issue? Do you have any links/tutorials on getting started with it? –  Justin Feb 9 '12 at 22:03
    
I don't think 100mbps caps should be much of an issue unless your files are very large, and even then, gluster won't be worse than trying to do with with rsync or nfs. I don't have any tutorials for gluster, sorry. –  cjc Feb 9 '12 at 22:21
add comment

http://www.csync.org/ is similar to rsync, but designed with this particular situation in mind; I think you might still need something to trigger it though, like incron

share|improve this answer
add comment

Do your source files change so frequently that you would even consider rsyncing every 3 seconds, or are these dynamically generated files?

If these are indeed source files you would be best off triggering a resync upon detecting a change in the file/folder last modified time.

If dynamically generated you should consider storing the content in a database shared by both machines and recreating them as files if the database version is newer than the physical file (compare a timestamp field to the file timestamp).

share|improve this answer
add comment

Just stumbled upon this answer while researching for my own solution. The problem with incron is that it does not monitor sub-directories and folders.

An alternative is lsyncd: http://code.google.com/p/lsyncd/

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.