用sersync工具来实现目录文件的同步

512638068 8年前

来自: http://blog.csdn.net//jiao_fuyou/article/details/46425577


前面一篇文章我们写了用rsync+inotify-tools来实现同步目录文件。
这一篇我们讲用sersync工具来实现目录文件的同步,该工具只更新变更的文件,不需要象rsync那样对目录做比较,具体介绍我不多说了,自己搜索就行了。

配置远程服务器的rsync

vi /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    [sync_test]  path=/home/jfy/tmptmp  comment  = jfy sync test  ignore errors = yes  read only = no  hosts allow = *  hosts deny = *

远程服务器启动rsync:rsync –daemon,默认监听在874端口
sync_test为一模块,指定了同步的目录/home/jfy/tmptmp

配置发送服务器sersync

<?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="/home/jfy/tmptmp">          <remote ip="172.16.18.116" name="sync_test"/>          <!--<remote ip="192.168.8.39" name="tongbu"/>-->          <!--<remote ip="192.168.8.40" name="tongbu"/>-->      </localpath>      <rsync>          <commonParams params="-artuz"/>          <auth start="false" users="root" passwordfile="/etc/rsync.pas"/>          <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>

该配置文件,实现监听/home/jfy/tmptmp目录,并同步到远程服务器的sync_test模块对应该的目录。

启动sersync:sersync2 -rdo ./confxml.xml

sersync工具具体使用请看,sersync2 完全安装配置说明sersync2二进制包下载