sync each other between two CentOS Linux Server

I have two PHP web server,now I need load balance,so I must keep web files all the same.

many ways I found,for example sshfs,rsync.

when sshfs I choosed,I found that the disk IO is slow.because two web server use one web files,the web files are shared by one of the servers by LAN.

rsync is not suited here.because I need the two servers can sync data to each other automotically,obvious,rsync just sync data from one to another,it is not I want.

finally,I found lsyncd and choose it.

it can sync data to each other automotically,that is I need.

first of all,you need to login to your system by ssh-key.so,you got a key in your current user’s directory,for example /root/.ssh/id_rsa.

OK,follow the step to setup lsyncd:
1.
yum install epel-release
yum install lsyncd

2.
vi /etc/lsyncd.conf

like this:

— User configuration file for lsyncd.

— Simple example for default rsync, but executing moves through on the target.

— For more examples, see /usr/share/doc/lsyncd*/examples/

–sync{default.rsyncssh, source=”/var/www/html”, host=”localhost”, targetdir=”/tmp/htmlcopy/”}
settings {
statusFile = “/tmp/lsyncd.stat”,
statusInterval = 1,
logfile =”/var/log/lsyncd.log”,
inotifyMode = “CloseWrite or Modify”,
maxProcesses = 5,
maxDelays = 1,
— nodaemon =true,
}

sync{
default.rsync,
source=”/data/wwwroot”,
target=”root@xx.xx.xx.xx.:/data/wwwroot”,
}

now,start your lsyncd service:
systemctl enable lsyncd
systemctl start lsyncd

go and look at your target directory,the files are there.

发表评论

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据