美文网首页
rsync+sersync实现远程同步

rsync+sersync实现远程同步

作者: uangianlap | 来源:发表于2017-02-05 22:22 被阅读158次

各主机IP

172.16.1.5   lb01
172.16.1.6   lb02
172.16.1.7   web02
172.16.1.8   web01
172.16.1.51  db01 
172.16.1.31  nfs01
172.16.1.41  backup
172.16.1.61  m01

sersync主要用于服务器同步,web镜像等功能。相当于之前我们使用的inotify-tools+rsync功能
sersync的优点

  • 其是使用C++编写,而且对Linux系统文件系统产生的临时文件和重复的文件操作进行过滤,同步时效率更高花时更少.
  • sersync配置简单.
  • 使用多线程进行同步,尤其在同步较大文件时能够保证多个服务器实时保持同步状态.
  • 有出错处理机制,通过失败队列对出错的文件重新同步.
  • 自带crontab功能,只需要在xml配置文件中开启
  • 支持插件,二次开发的需要

sersync的使用(rsync客户端主机上,本例是nfs01)

准备sersync软件,点击链接下载: sersync_64bit_binary_stable_final.tar.gz
tar -zxvf sersync_64bit_binary_stable_final.tar.gz -C /usr/local/sersync
里面有两个文件
confxml.xml 配置文件
sersync2 二进制程序

SETP1:编辑配置文件confxml.xml如下部分:

    <filter start="false">
        <exclude expression="(.*)\.svn"></exclude>
        <exclude expression="(.*)\.gz"></exclude>
        <exclude expression="^info/*"></exclude>
        <exclude expression="^static/*"></exclude>
    </filter>
    <inotify>
        <delete start="true"/>
        <closeWrite start="true"/>
        <moveFrom start="true"/>
        <moveTo start="true"/>
        <attrib start="false"/>
        <modify start="false"/>
    </inotify>
    <sersync>
        <localpath watch="/data">
            <remote ip="172.16.1.41" name="nfsbkup"/>
            <!--<remote ip="192.168.8.39" name="tongbu"/>-->
            <!--<remote ip="192.168.8.40" name="tongbu"/>-->
        </localpath>
        <rsync>
            <commonParams params="-avz"/>
            <auth start="true" users="rsync_backup" passwordfile="/etc/rsync.password"/>
            <userDefinedPort start="false" port="874"/><!-- port=874 -->
            <timeout start="true" time="100"/><!-- timeout=100 -->
            <ssh start="false"/>
        </rsync>
        <failLog path="/application/logs/rsync_fail_log.sh" timeToExecute="60"/><!--default ever
y 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>

remote ip即为rsync Server
name为rsync Server配置文件中指定的模块名
auth 标签里的user为rsync Server配置文件里指定的auth user

STEP2: 执行sersync
cd /usr/local/sersync
./sersync2 -o confxml.xml -n 10 -d
OK!!

sersync的参数说明:
    -o: 指定使用的xml配置文件,默认使用confxml.xml文件
    -n: 指定开启守护线程的数量,默认为10个
    -d:启用守护进程模式
    -m:单独启用其他模块,
        使用 -m refreshCDN 开启刷新CDN模块
        使用 -m socket 开启socket模块
        使用 -m http 开启http模块
        加-m参数,则默认执行同步程序

相关文章

网友评论

      本文标题:rsync+sersync实现远程同步

      本文链接:https://www.haomeiwen.com/subject/uifyittx.html