Load Balancing + Folder sync

apache-2.2load balancingrsyncsynchronizationunison

i've 2 servers.

  1. Server A : contains
    • mysql
    • apache
    • nginx
  2. Server B : contains
    • apache
    • memcached
    • rsync cron ( each 3 mins ) that pulls the /var/www/ content and update its own

I'm using:

  • nginx of Server A to load balance the http requests. (And it work just fine).
  • memcached from server B to maintain php sessions

Nginx currently load balances asking Server B to handle 75% of the requests.

In order to sync the application code ( which is written in php ) i use rsync ( as explained above ).

The problem of rsync is that I can't handle 2 way sync so I was starting looking at Unison.

At this point I've 2 questions:

  1. Would it be a good idea to ask nginx to route all the "send file" requests to Server A so that Server B only needs to pull?
  2. Should I use Unison or some other software for this kind of sync? Can I get a realtime sync?
  3. Should I use some network file system that shares the content of /var/www/ from Server A to Server B? If yes. What do you suggest?

Best Answer

You can use tools rsync or unison, but you will not get a realtime sync. There should be some delay until new/updated files get synced even if you run such a tool every minute. You can implement it if you think it is acceptable to have a small delay.

If you want to get changes synced in realtime, you need to use a tool like NFS/glusterfs, or DRBD. The main drawback of such tools is the increased I/O overhead as a result of network delay. This becomes clearer when the shared folder becomes huge and network delay becomes larger.