sersync是基于inotify+rsync的大量文件的多服务器自动同步程序 使用 Linux 2.6 内核的 inotify 监控 Linux 文件系统事件,被监听目录下如果有文件发生修改,sersync 将通过内核自动捕获到事件,并将该文件利用 rsync 同步到多台远程服务器。sersync 仅仅同步发生增、删、改事件的单个文件或目录,不像rsync镜像同步那样需要比对双方服务器整个目录下数千万的文件,并且支持多线程同步,因此效率非常高。 sersync已不在更新,感谢sersync作者周洋 谷歌项目地址:https://code.google.com/archive/p/sersync/ 64位下载地址:https://storage.googleapis.com/google-code-archive-downloads/v2/code.google.com/sersync/sersync2.5.4_64bit_binary_stable_final.tar.gz 32位下载地址:https://storage.googleapis.com/google-code-archive-downloads/v2/code.google.com/sersync/sersync2.5_32bit_binary_stable_final.tar.gz 上不去google的可以直接wget我本地的包,这里只提供64位版本的:http://down.whsir.com/downloads/sersync2.5.4_64bit_binary_stable_final.tar.gz 压缩包里面有两个文件confxml.xml sersync2 sersync2 这个是sersync主程序 confxml.xml 这个是sersync配置文件 配置文件部分常用参数解释: <?xml version="1.0" encoding="ISO-8859-1"?> <head version="2.5"> <host hostip="localhost" port="8008"></host> #保留字段,默认即可 <debug start="false"/> #是否开启调试模式,默认false即可 <fileSystem xfs="true"/> #是否开启支持xfs文件系统,Centos7默认都是xfs的了,所以建议true开启 <filter start="false"> #是否开启过滤模式,根据需求开启,例:过滤以.php结尾的文件(.).php <exclude expression="(.).svn"></exclude> #过滤以.svn结尾的文件 <exclude expression="(.).gz"></exclude> #过滤以.gz结尾的文件 <exclude expression="^info/"></exclude> #过滤监控目录下的info路径 <exclude expression="^static/"></exclude> #过滤监控目录下的static路径 <exclude expression="wwwroot/blogwhsir/"></exclude> #过滤wwwroot/blogwhsir/目录下所有文件 </filter> <inotify> #inotify监控事件 <delete start="true"/> #如果不开启此项,在删除监控目录下的文件时,目标服务器的文件则不会同时删除,根据需求开启 <createFolder start="true"/> #不开启不能监控子目录,建议true <createFile start="false"/> #关闭提高通讯性能,默认就好 <closeWrite start="true"/> <moveFrom start="true"/> <moveTo start="true"/> <attrib start="false"/> <modify start="false"/> </inotify>

<sersync> <localpath watch="/opt/tongbu"> #指定要监控的本地目录 <remote ip="127.0.0.1" name="tongbu1"/> #指定要同步的目标服务器的IP地址,及目标服务器rsync的[模块] <!--<remote ip="192.168.8.39" name="tongbu"/>--> <!--<remote ip="192.168.8.40" name="tongbu"/>--> </localpath> <rsync> #配置rsync <commonParams params="-artuz"/> #rsync的参数 <auth start="false" users="root" passwordfile="/etc/rsync.pas"/> #是否开启rsync的认证模式,需要配置users及passwordfile,根据情况开启(如果开启,注意密码文件权限一定要是600) <userDefinedPort start="false" port="874"/><!-- port=874 --> #远程目标服务器的端口不是默认端口时使用 <timeout start="false" time="100"/><!-- timeout=100 --> #是否开启rsync的超时时间 <ssh start="false"/> </rsync> <failLog path="/tmp/rsync_fail_log.sh" timeToExecute="60"/><!--default every 60mins execute once--> #目标服务器传输失败时会重新传输,再次失败会写入rsync_fail_log中,每隔一段时间(timeToExecute)执行脚本再次传输 <crontab start="false" schedule="600"><!--600mins--> #对监控目录与目标服务器每隔一段时间进行一次整体同步,默认600分钟,根据个人情况是否开启 <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="https://blog.whsir.com"/> <regexurl regex="false" match="cms.xoyo.com/site([/a-zA-Z0-9]*).xoyo.com/images"/> </localpath> </plugin> </head>