1

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.

5 Answers 5

3

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:$@
2
  • 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, 2012 at 23:26
  • should the end of that line really be /srv and not /srv/ or /srv/www
    – stew
    Feb 10, 2012 at 1:04
1

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.

2
  • 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, 2012 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, 2012 at 22:21
1

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

1

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).

0

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/

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .