用sersync工具來實現目錄文件的同步

512638068 8年前發布 | 7K 次閱讀 Linux

來自: 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 = </pre>

遠程服務器啟動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></pre>

該配置文件,實現監聽/home/jfy/tmptmp目錄,并同步到遠程服務器的sync_test模塊對應該的目錄。

啟動sersync:sersync2 -rdo ./confxml.xml

sersync工具具體使用請看,sersync2 完全安裝配置說明sersync2二進制包下載

</div>

 本文由用戶 512638068 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
 轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
 本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!