Load balancing for MySQL

Hi all,

I have made with success a load balance between my Master and Slave ( Backup server ), to copy each hour the “root files” inside a copy, to be more clear to copy everything in the domain. THis is the code :

10 * * * * rsync -av -e "ssh -p 22 -i /root/.ssh/id_dsa" /var/www/vhosts/mydomain/* xx.xxx.xxx.xx:/var/www/vhosts/mydomain/ 

NB : for security raison, I replace my website name here by ( mydomain) and the IP of the backup server by ( xx.xxx.xxx.xx )

Now the important question is the following : As I’m using this code to copy everything inside my website folder in vhosts folder, is that possible to do the same with the database with something like the following ??

10 * * * * rsync -av -e "ssh -p 22 -i /root/.ssh/id_dsa" /var/lib/mysql/* xx.xxx.xxx.xx:/var/lib/mysql/ 

To copy all the files inside MYSQL folder on the master server to the MYSQL folder on the slave server ?

Thanks for your help and advice.

Please, oh, please don’t do that! There is proper replication in MySQL to do exactly this and keep it up-to-date in realtime, i.e., when you insert something to the master, it will directly thereafter be copied to the slave, all updates will be propagated immediately, etc. The only thing need to make sure is to write to the master only, not to any of the slaves.

For example take a look at this tutorial: https://www.digitalocean.com/community/tutorials/how-to-set-up-master-slave-replication-in-mysql

With regards to copying the code, will it be updated so much that you need to copy it every 10 minutes? Isn’t it possible that when you put some new code only to deploy to both servers at once? There are a lot of deploy tools out there that could easily do that for you, like phing or capistrano.

If you don’t want to use a build tool I’d at least look at inotifywatch to see when files have changed so you can rsync them over instead of rsyncing all files every 10 minutes.

Thank you so much ScallioXTX for your feedback and advice, I will follow the tutorial that you mentioned on digitalocean.

[quote=“rpkamp, post:2, topic:116618”]
will it be updated so much that you need to copy it every 10 minutes?
[/quote] oh I thought it will be updated each hour, how can I fix that ?

To be honest, I dont know them, but I will take a look, to have an idea how they work and if they are cheap.

Oh my bad, it is indeed every hour (I thought you put */10 instead of just 10; */10 is every 10 minutes, 10 is every 10 minutes past any hour).

They’re free :wink:

There is no problem at all :wink:

Amazing, thanks

Hi,

Is the following method works for CentOS Lunix as it works here for Ubuntu Lunix ?

The commands may differ slightly, but the idea is the same, yes :slight_smile:

Thank you for your support Scallio

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.