zoukankan      html  css  js  c++  java
  • Sersync实现触发式文件同步 替代inotify和rsync

    Sersync实现触发式文件同步 替代inotify和rsync


    Pyinotify是一个Python模块,用来监测文件系统的变化。 Pyinotify依赖于Linux内核的功能—inotify(内核2.6.13合并)。 inotify的是一个事件驱动的通知器,其通知接口通过三个系统调用从内核空间到用户空间。pyinotify结合这些系统调用,并提供一个顶级的抽象和一个通用的方式来处理这些功能。
    pyinotify其实就是通过调用系统的inotify来实现通知的。 http://my.oschina.net/zhangxu0512/blog/382867
    你好。rsync的LINUX端,cwrsync的windows 端,windows 向LINUX传中文文件时总是乱码,添加--iconv=utf-8也不行

    参考文章

    http://blog.chinaunix.net/uid-20639775-id-3011124.html

    http://www.apelearn.com/bbs/forum.php?mod=viewthread&tid=10738&page=1&extra=#pid113148

    http://zyan.cc/sersync/

    mrsync https://sourceforge.net/projects/mrsync/


    服务器端
    1、安装rsync  两边都要做
    yum install -y rsync
    vi /etc/rsyncd.conf #服务器端
    port=873
    log file=/var/log/rsync.log
    pid file=/var/run/rsyncd.pid
    #address=192.168.0.10
    max connections=0
    timeout = 300
    [webbak]
    path=/tmp/www/wordpress
    use chroot=true
    read only=no
    list=false
    uid=root
    gid=root
    #auth users=test
    #secrets file=/etc/rsyncd.passwd
    hosts allow=192.168.1.109
    #hosts deny = 0.0.0.0/32

    #设置开机启动
    echo "rsync --daemon" >>/etc/rc.local
    #启动服务
    rsync --daemon


    2、安装Inotify-tools工具,实时触发rsync进行同步
    两边机器都要做
    安装inotify-tools
    yum install -y make gcc gcc-c++
    cd /mydata/download/
    wget -c http://github.com/downloads/rvoicilas/inotify-tools/inotify-tools-3.14.tar.gz
    tar zxvf inotify-tools-3.14.tar.gz
    cd inotify-tools-3.14
    mkdir -p /usr/local/inotify
    ./configure --prefix=/usr/local/inotify
    make
    make install
    设置系统环境变量,添加软连接
    echo "PATH=$PATH:/usr/local/inotify/bin" >>/etc/profile.d/inotify.sh
    source /etc/profile.d/inotify.sh #使设置立即生效
    echo "/usr/local/inotify/lib" >/etc/ld.so.conf.d/inotify.conf && ldconfig
    ln -s /usr/local/inotify/include /usr/include/inotify
    修改inotify默认参数(inotify默认内核参数值太小)
    vi /etc/sysctl.conf
    fs.inotify.max_queued_events=99999999
    fs.inotify.max_user_watches=99999999
    fs.inotify.max_user_instances=65535
    /sbin/sysctl -p


    客户端

    3、安装配置sersync
    cd /download
    wget -c https://storage.googleapis.com/google-code-archive-downloads/v2/code.google.com/sersync/sersync2.5.4_64bit_binary_stable_final.tar.gz


    tar -zxvf sersync2.5.4_64bit_binary_stable_final.tar.gz
    mv GNU-Linux-x86 /usr/local/sersync

    vi /usr/local/sersync/webbakconfxml.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="true">
    <exclude expression="(.*)wp-config.php"></exclude>
    <!-- <exclude expression="(.*).gz"></exclude>-->
    <!-- <exclude expression="^info/*"></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="true"/>
    </inotify>

    <sersync>
    <localpath watch="/webbak">
    <remote ip="192.168.14.91" name="webbak"/>
    <!--<remote ip="192.168.1.12" name="tongbu"/>-->
    <!--<remote ip="192.168.1.13" name="tongbu"/>-->
    </localpath>
    <rsync>
    <commonParams params="-az"/>
    <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/sersync_fail_log.sh" timeToExecute="60"/><!--default every 60min execute once-->
    <crontab start="true" schedule="720"><!--720mins-->
    <crontabfilter start="true">
    <exclude expression="wp-config.php"></exclude>
    <!--<exclude expression="*.gz"></exclude>-->
    <!--<exclude expression="info/*"></exclude>-->
    </crontabfilter>
    </crontab>

    </sersync>
    </head>


    将命令添加进/etc/rc.local,以后重启系统以后才能正常同步
    vi /etc/rc.local
    /usr/local/sersync/sersync2 -d  -o /usr/local/sersync/webbakconfxml.xml

    先测试一下rsync同步是否正常
    rsync -av /tmp/ntpdate.log  192.168.14.91::webbak

     



    配置环境变量
    echo "export PATH=$PATH:/usr/local/sersync/bin" >>/etc/profile
    source /etc/profile

     

    4、脚本监控sersync
    因为有的时候sersync脚本会自动关掉,因此需要写一个脚本自动的去检测该进程是否存在,不存在就启动,脚本内容如下:
    vi /root/check_sersync.sh
    #!/bin/bash
    #Purpose: Check sersync whether it is alive
    #Author: steven
    SERSYNC="/usr/local/sersync/sersync2"
    CONF_FILE="/usr/local/sersync/confxml.xml"
    STATUS=$(ps aux |grep 'sersync2'|grep -v 'grep'|wc -l)
    if [ $STATUS -eq 0 ];
    then
    $SERSYNC -d -r -o $CONF_FILE &
    else
    exit 0;
    fi

    脚本写好以后,添加到计划任务中去
    crontab -e
    */1 * * * * /bin/sh /root/check_sersync.sh > /dev/null 2>&1



    参数
    -d 后台运行
    -r 本地和目标进行一次整体同步,如果设置了<filter start="false">,那么暂时不能使用-r参数进行整体同步
    -o xml配置文件位置
    -n 线程数,机器配置高可以设置大一点
    -m 插件
    --help  查看帮助



    rsyncd.conf里max connections=0 最好设置为0


    其他实时同步解决方案一览
    lsyncd1.4.2+rsync 同步数据
    csync2+inotify 同步数据
    csync2+lsyncd 同步数据
    inotify+rsync 同步数据
    DRBD 同步数据  缺点是备节点不能用

    http://blog.johntechinfo.com/sersyncguild
    http://blog.johntechinfo.com/technology/155

    老男孩

    f

  • 相关阅读:
    进程、线程、协程
    C++内存模型
    动态库dll与静态库lib
    virtual 虚函数表
    C++面试随笔
    alloc()、malloc()、calloc()、realloc()区别及用法
    C/C++ 面试题记录
    VC底层钩子程序在Win7/Vista下无效
    JMeter安装之后修成中文版
    明天开始 新的旅程
  • 原文地址:https://www.cnblogs.com/MYSQLZOUQI/p/5188407.html
Copyright © 2011-2022 走看看