0

i have 2 server with public ip:

SERVER A - 10.10.10.11
SERVER B - 10.10.10.12

both of them are centos 6 in OS, installed nginx with php-fpm, 2 exact same website stored at: /var/www/html.

Domain with: myxdomain.com and dns hosted with cloudflare ( since cloudflare do support round robin ) to point the domain to A record of 10.10.10.11 and 10.10.10.12. I know that round robin dns does not cover the failover or fallover, but it does not matter, what i need is:

How do i sync the both content of /var/www/html server A and server B to be exactly same? Lets say:

1) user uploaded their file to server A, the file content will be sync to server B as well.
2) user uploaded their file to server B, the file content will be sync to server A as well.

rsync will be good choice here? Any example of command line and cronjob time that suitable?

thanks

0

6 Answers 6

2

Try:

rsync -vaEW source destination

Same on the other side, of course.

4
  • what is the best time for sync it? every 5 minute on server A to download from Server B and every 10 minute from Server B to download server A?
    – Teddybugs
    Nov 6, 2013 at 2:10
  • Good point. Depends on how many files you expect to see added in-between. So that would basically mean 5 minutes to merge A into B. Sounds like a good start since frequent sync may mean less time anyway (less content).
    – Eduardo
    Nov 6, 2013 at 2:16
  • with your rsync command how to handle file deletion? lets say server A deleted some files, it need to be deleted on Server B as well
    – Teddybugs
    Nov 6, 2013 at 2:30
  • 1
    add "--delete" flag to rsync cmd. there may be shorter version
    – nandoP
    Nov 6, 2013 at 8:39
2

Check this link: http://howtodba.com/how-to-build-a-cheap-web-cluster-with-replicated-storage-and-mysql-master-master-configuration/

Read the Step 4: Install GlusterFS server and client

I've used that tutorial for a master-master web cluster, with replicated storage via GlusterFS.

1
  • Some sort of shared/distributed storage is probably the way to go, but there are a number of pitfalls for running PHP apps on top of GlusterFS. You probably want to use rsync or something similar for code deployments, and GlusterFS for static files that should be shared among hosts.
    – GomoX
    Nov 6, 2013 at 15:49
0

I would be evaluating Bittorrent Sync here; it will handle 2 way "multi-master" synchronization, without a 3rd party cloud too.

You can set it up to only sync with specific hosts, so you will only be syncing with the other node.

0

1) set up pki. this makes "interactive" ssh login is not required. this can be done with ssh-keygen, and pasting the newly generated ~/.ssh/id_dsa.pub or ~/.ssh/id_rsa.pub in ~/.ssh/authorized_keys on remote box.

2) set up cron to rsync contents over every however often. whether cron'd or not, the rsync command is the same as stated earlier. depending on how much verbosity you want, try:

user@serverB> rsync -avP /var/www/html/ user@serverA:/var/www/html/
user@serverA> rsync -avP /var/www/html/ user@serverB:/var/www/html/

if the cron/script is running as "user", you can omit that part, however "user" must have .ssh/authorized_keys in their home dir for this to be passwordless (and automated)

0

If you really want the LB that way - try csync It uses rsync protocol but it's made for bidirectional synchronisation

0

Another option would be to use unison. It's like rsync, but can handle two way syncing (deletes).

2
  • rsync can handle delete as well
    – Teddybugs
    Nov 7, 2013 at 1:19
  • Yes, but not the way unison does (two way syncing - it saves the last state and can figure out what to do in complex situations).
    – Jure1873
    Nov 7, 2013 at 20:44

You must log in to answer this question.

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