rsync+sersync

rsync+inotify的缺点/不足

1.Inotify-tools只能记录下被监听的目录发生了变化(增删改等),并没有把具体是哪个文件或者哪个目录发生了变化记录下来

2.rsync在同步的时候,并不知道具体是哪个文件或者哪个目录发生了变化,每次都是对整个目录进行同步,当数据量很大时,整个目录同步非常耗时(rsync要对整个目录遍历查找对比文件),效率很低。

rsync+sersync解决了这些不足:

1.sersync可以记录下被监听目录中发生变化的(增删改等)具体某一个文件或某一个目录的名字

2.rsync在同步的时候,只同步发生变化的这个文件或者这个目录(每次发生变化的数据相对整个同步目录数据来说是很小的,rsync在遍历查找比对文件时,速度很快),效率高。

架构图

image.png

部署rsync+sersync

1.在136机器上部署rsync,请参考http://blog.51cto.com/12107790/2310552

2.在140机器上部署rsync和sersync


[root@Management-Machine-140 backup]# wget http://down.whsir.com/downloads/sersync2.5.4_64bit_binary_stable_final.tar.gz 
[root@Management-Machine-140 backup]# tar -zxvf sersync2.5.4_64bit_binary_stable_final.tar.gz -C /usr/local/src
[root@Management-Machine-140 backup]# mv sersync /usr/local/sersync
[root@Management-Machine-140 backup]# 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="true"/>
        <closeWrite start="true"/>
        <moveFrom start="true"/>
        <moveTo start="true"/>
        <attrib start="false"/>
        <modify start="false"/>
    </inotify>
    <sersync>                                            #监控的目录和同步到哪个ip和块
        <localpath watch="/data/backup">
            <remote ip="192.168.146.136" name="rsync-test"/>
            <!--<remote ip="192.168.8.39" name="tongbu"/>-->
            <!--<remote ip="192.168.8.40" name="tongbu"/>-->
        </localpath>
        <rsync>                                        #rsync使用的参数
            <commonParams params="-az"/>
            <auth start="true" users="rsync-webA" passwordfile="/etc/webA.pass"/>    #是否进行验证
            <userDefinedPort start="false" port="22"/><!-- port=874 -->              #使用的端口
            <timeout start="false" time="100"/><!-- timeout=100 -->                  #超时设置
            <ssh start="false"/>                                                     #是否启用ssh
        </rsync>
        <failLog path="/tmp/rsync_fail_log.sh" timeToExecute="60"/><!--default every 60mins execute once-->
        <crontab start="false" schedule="600"><!--600mins-->                            #crontab
            <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">                                #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>

查看帮助和进行监控

[root@Management-Machine-140 backup]# sersync -h
set the system param
execute:echo 50000000 > /proc/sys/fs/inotify/max_user_watches
execute:echo 327679 > /proc/sys/fs/inotify/max_queued_events
parse the command param
_______________________________________________________
参数-d:启用守护进程模式
参数-r:在监控前,将监控目录与远程主机用rsync命令推送一遍
c参数-n: 指定开启守护线程的数量,默认为10个
参数-o:指定配置文件,默认使用confxml.xml文件
参数-m:单独启用其他模块,使用 -m refreshCDN 开启刷新CDN模块
参数-m:单独启用其他模块,使用 -m socket 开启socket模块
参数-m:单独启用其他模块,使用 -m http 开启http模块
不加-m参数,则默认执行同步程序
________________________________________________________________

[root@Management-Machine-140 backup]# sersync -d -r -o /usr/local/sersync/confxml.xml &

测试:

[root@Management-Machine-140 backup]# touch test.log

在136上查看是否有test.log

[root@WebA-136 sersync]# ls
test.log


猜你喜欢

转载自blog.51cto.com/12107790/2314023