一、为什么要用Rsync+sersync架构?
1、sersync是基于Inotify开发的,类似于Inotify-tools的工具 2、sersync可以记录下被监听目录中发生变化的(包括增加、删除、修改)具体某一个文件或某一个目录的名字,然后使用rsync同步的时候,只同步发生变化的这个文件或者这个目录。 二、Rsync+Inotify-tools与Rsync+sersync这两种架构有什么区别? 1、Rsync+Inotify-tools (1):Inotify-tools只能记录下被监听的目录发生了变化(包括增加、删除、修改),并没有把具体是哪个文件或者哪个目录发生了变化记录下来; (2):rsync在同步的时候,并不知道具体是哪个文件或者哪个目录发生了变化,每次都是对整个目录进行同步,当数据量很大时,整个目录同步非常耗时(rsync要对整个目录遍历查找对比文件),因此,效率很低。 2、Rsync+sersync (1):sersync可以记录下被监听目录中发生变化的(包括增加、删除、修改)具体某一个文件或某一个目录的名字; (2):rsync在同步的时候,只同步发生变化的这个文件或者这个目录(每次发生变化的数据相对整个同步目录数据来说是很小的,rsync在遍历查找比对文件时,速度很快),因此,效率很高。 小结:当同步的目录数据量不大时,建议使用Rsync+Inotify-tools;当数据量很大(几百G甚至1T以上)、文件很多时,建议使用Rsync+sersync。 #来源网络
1.环境,以及软件
web1:192.168.50.125 web2:192.168.50.126
软件:
wget http://sersync.googlecode.com/files/sersync2.5_64bit_binary_stable_final.tar.gz
#安装rsync+sersync实现web1自动同步代码到web2中
2.web1 yum -y install rsync 编辑修改配置文件
vim /etc/rsyncd.conf
uid = goforit
gid = goforit
port = 873
max connections = 2000
use chroot = yes
timeout = 200
log file = /var/log/rsyncd.log
pid file = /var/run/rsyncd.pid
lock file = /var/run/rsyncd.lock
log format = %t %a %m %f %b
#auth users = goforit
#secrets file = /etc/rsyncd.secret #goforit:123456
[goforit_web] #模块配置
path = /usr/local/data/www #本地web路径
comment = "www directory file" #提示信息
list = yes
read only = no
ignore errors = yes
hosts allow = 192.168.50.126
hosts deny = *
exclude = #可以设置过滤文件或者目录
安装sersync
tar -zxf sersync2.5_64bit_binary_stable_final.tar.gz
mv GNU-Linux-x86 /usr/local/data/sersync
该目录中文件,一个是配置文件,一个是命令
confxml.xml sersync2
修改配置文件confxml.xml
<localpath watch="/usr/local/data/www">
<remote ip="192.168.50.125" name="goforit_web"/> #设置需要同步的服务器地址(目标地址)
</localpath>
<localpath watch="/usr/local/data/www"> #本地需要同步的目录
<remote ip="192.168.50.126" name="my"/> #远程web服务器IP,以及rsync模块名
<auth start="true" users="hckj164" passwordfile="/etc/rsync.pas"/> #设置用于同步的用户名和密码 #密码可以不设置
...
<failLog path="/usr/local/data/sersync/rsync_fail_log.sh" timeToExecute="60"/> #
启动sersync
/usr/local/data/sersync/sersync2 -d -r -o /usr/local/data/sersync/confxml.xml
web2:
yum -y install rsync
编辑修改配置文件
vim /etc/rsyncd.conf
uid = goforit
gid = goforit
port = 873
max connections = 2000
use chroot = yes
timeout = 200
log file = /var/log/rsyncd.log
pid file = /var/run/rsyncd.pid
lock file = /var/run/rsyncd.lock
log format = %t %a %m %f %b
#auth users = goforit
#secrets file = /etc/rsyncd.secret #goforit:123456
[goforit_web] #模块配置
path = /usr/local/data/www #本地web路径
comment = "www directory file" #提示信息
list = yes
read only = no
ignore errors = yes
hosts allow = 192.168.50.125
hosts deny = *
exclude = #可以设置过滤文件或者目录