参考网站
http://blog.csdn.net/tin591/article/details/12514951
http://blog.johntechinfo.com/sersyncguild
原理:
使用 Linux 2.6 内核的 inotify 监控 Linux 文件系统事件,被监听目录下如果有文件发生修改,sersync 将通过内核自动捕获到事件,并将该文件利用 rsync 同步到多台远程服务器。sersync 仅仅同步发生增、删、改事件的单个文件或目录,不像rsync镜像同步那样需要比对双方服务器整个目录下数千万的文件,并且支持多线程同步,因此效率非常高。
server推送端配置
yum -y install rsync
下载sersync源码包
sersync2.5.4_64bit_binary_stable_final.tar.gz
tar -xvzf sersync2.5.4_64bit_binary_stable_final.tar.gz
cd GNU-Linux-x86/
cp confxml.xml /usr/local/sersync/
cp sersync2 /usr/local/sersync/
echo "123456" >/etc/rsync.pas
chmod 600 /etc/rsync.pas
vim confxml.xml
<?xml version="1.0" encoding="ISO-8859-1"?>
<head version="2.5">
<host hostip="localhost" port="8008"></host>
<debug start="false"/>
<fileSystem xfs="false"/>
<filter start="false">
<exclude expression="(.*)\.svn"></exclude>
<exclude expression="(.*)\.gz"></exclude>
<exclude expression="^info/*"></exclude>
<exclude expression="^static/*"></exclude>
</filter>
<inotify>
<delete start="true"/>
<createFolder start="true"/>
<createFile start="false"/>
<closeWrite start="true"/>
<moveFrom start="true"/>
<moveTo start="true"/>
<attrib start="false"/>
<modify start="false"/>
</inotify>
<sersync>
<localpath watch="/data">
<remote ip="192.168.199.212" name="data"/>
</localpath>
<rsync>
<commonParams params="-auvzP"/>
<auth start="true" users="zhaochao" passwordfile="/etc/rsync.pass"/>
<userDefinedPort start="false" port="874"/><!-- port=874 -->
<timeout start="false" time="100"/><!-- timeout=100 -->
<ssh start="false"/>
</rsync>
<failLog path="/tmp/rsync_fail_log.sh" timeToExecute="60"/><!--default every 60mins execute once-->
<crontab start="false" schedule="600"><!--600mins-->
<crontabfilter start="false">
<exclude expression="*.php"></exclude>
<exclude expression="info/*"></exclude>
</crontabfilter>
</crontab>
<plugin start="false" name="command"/>
</sersync>
<plugin name="command">
<param prefix="/bin/sh" suffix="" ignoreError="true"/> <!--prefix /opt/tongbu/mmm.sh suffix-->
<filter start="false">
<include expression="(.*)\.php"/>
<include expression="(.*)\.sh"/>
</filter>
</plugin>
<plugin name="socket">
<localpath watch="/opt/tongbu">
<deshost ip="192.168.138.20" port="8009"/>
</localpath>
</plugin>
<plugin name="refreshCDN">
<localpath watch="/data0/htdocs/cms.xoyo.com/site/">
<cdninfo domainname="ccms.chinacache.com" port="80" username="xxxx" passwd="xxxx"/>
<sendurl base="http://pic.xoyo.com/cms"/>
<regexurl regex="false" match="cms.xoyo.com/site([/a-zA-Z0-9]*).xoyo.com/images"/>
</localpath>
</plugin>
</head>
只需要更改IP和同步的目录 就好
/usr/local/sersync/bin/sersync2 -r -d -o /usr/local/sersync/conf/confxml.xml
在被推动端安装rsync
yum -y install rsync
vim /etc/rsyncd.conf
uid=root
gid=root
max connections=36000
use chroot=no
log file=/var/log/rsyncd.log
pid file=/var/run/rsyncd.pid
lock file=/var/run/rsyncd.lock
[data]
path=/data
comment = This is test
ignore errors = yes
read only = no
auth users= zhaochao
secrets file = /etc/rsync.pas
###密码文件权限必须为600 zhaochao:123456
hosts allow=192.168.199.201/24
hosts deny=*
rsync --daemon --config=/etc/rsyncd.conf
hosts deny=*
rsync --daemon --config=/etc/rsyncd.conf