• sersync+rsync原理及部署


    一、为什么要用rsync+sersync架构?

    1、sersync是基于inotify开发的,类似于inotify-tools的工具

    2、sersync可以记录下被监听目录中发生变化的(包括增加、删除、修改)具体某一个文件或者某一个目录的名字,然后使用rsync同步的时候,只同步发生变化的文件或者目录

    二、rsync+inotify-tools与rsync+sersync架构的区别?

    1、rsync+inotify-tools

     a、inotify只能记录下被监听的目录发生了变化(增,删,改)并没有把具体是哪个文件或者哪个目录发生了变化记录下来;

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

        

    2、rsync+sersync

     a、sersync可以记录被监听目录中发生变化的(增,删,改)具体某个文件或目录的名字;

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

    总结: 

                当同步的目录数据量不大时,建议使用rsync+inotify 

                当同步的目录数据量很大时(几百G甚至1T以上)文件很多时,建议使用rsync+sersync

    三、安装配置

    1、配置xinetd

    a)、配置xinetd

    vim /etc/xinetd.d/rsync
    # default: off
    # description: rsync file transfer daemon
    service rsync
    {
        socket_type    = stream
        protocol    = tcp
        wait        = no
        user        = root
        server        = /usr/sbin/rsyncd
        server_args    = --daemon
        disable        = no
    }

    b)、重启xinetd

    service xinetd restart

    2、配置rsync-server

    a)、rsync配置

    vim /etc/rsyncd.conf
    uid = root
    gid = root
    log format = %h %o %f %l %b
    log file = /var/log/rsyncd.log
    pid file = /var/run/rsyncd.pid
    hosts allow = 60.24.64.0/24,127.0.0.1
    read only = false
    list = false
    
    [xue]
    path = /xue
    comment = An Example
    auth users = work
    secrets file = /etc/rsyncd.secrets

    b)、密码文件/etc/rsyncd.secrets

    vim /etc/rsyncd.secrets
    work:123

    注意:权限为600,属组,属主为root

    3、rsync-client配置

    a)、配置rsync

    vim /passwd.txt
    123

    注意:客户端只需要密码,不需要用户名,权限为600,属组,属主为root

    b)、验证

    rsync -auvzP /data/ work@127.0.0.1::sunfcbp/ --password-file=/passwd.txt

    4、安装sersync

    a)、下载sersync

    地址:http://sersync.googlecode.com/files/sersync2.1_64bit_binary.tar.gz

    b)、解压,移动

    tar xf XXXX
    cp -R sersync /usr/local/

    c)、配置环境变量

    echo "PATH=$PATH:/usr/local/sersync" >>/etc/profile
    source
    /etc/profile

    d)、配置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="true"/>
        <modify start="false"/>
        </inotify>
    
        <sersync>
        <localpath watch="/a/">
            <remote ip="127.0.0.1" name="xue"/>
            <!--<remote ip="192.168.8.39" name="tongbu"/>-->
            <!--<remote ip="192.168.8.40" name="tongbu"/>-->
        </localpath>
        <rsync>
            <commonParams params="-artuzPv"/>
            <auth start="true" users="work" passwordfile="/passwd.txt"/>
            <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="true" 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>

    inotifywait events事件说明

    e)、同步

    sersync2 -r -d -o /usr/local/sersync/confxml.xml

  • 相关阅读:
    windows下部署MySQL 8.0.11
    基于beego构建Restful API服务
    Go 并发
    Go语言的面向对象(OOP)
    Go基础语法纪要
    软件工程基础图式(第四章 系统设计-面向过程的系统设计)
    概率论与数理统计图式(第三章 多维随机变量)
    编译技术图式(第四章 语法分析)01文法和语法的定义
    计算机组成原理和结构图式(第三章 CPU子系统)
    Java图式(第三章 流程控制、数组)
  • 原文地址:https://www.cnblogs.com/xue0123/p/7447208.html
Copyright © 2020-2023  润新知