zoukankan      html  css  js  c++  java
  • rsync + inotify 同步

    1. 配置rysnc server:同步机,同步被同步机更新的文件,很多台
    vi /etc/rsyncd.conf
    uid=root
    gid=root
    use chroot=no
    max connections=10
    timeout=600
    strict modes=yes
    port=873
    pid file=/var/run/rsyncd.pid
    lock file=/var/run/rsyncd.lock
    log file=/var/log/rsyncd.log
    [module_pk10]
    path=/data/www/DePK10
    comment=rsync pk10 unity
    auth users=pk10
    uid=root
    gid=root
    secrets file=/etc/rsyncd.secrets
    read only=no
    list=no
    hosts allow=103.x.x.x
    hosts deny=0.0.0.0/32

     vi /etc/rsyncd.secrets
    pk10:Lishen@123
    chmod 600 /etc/rsyncd.secrets

    启动:rsync --daemon

    添加防火墙开放 873端口
    -A INPUT -m state --state NEW -m tcp -p tcp -s 103.x.x.x --dport 873 -j ACCEPT

    2. 客户端:被同步机一台,更新文件只需要更新到这台
    vi /etc/rsync_client.pwd
    Lishen@123
    chmod 600 /etc/rsync_client.pwd

    mkdir  /etc/rsyncd.d/
    touch  /etc/rsyncd.d/rsync_exclude.lst

    安装inotify:yum install -y inotify-tools

    监控和同步脚本:
    vi rsync.sh
    #rsync auto sync script with inotify

    #variables
    current_date=$(date +%Y%m%d_%H%M%S)
    source_path=/data/www/DePK10/
    log_file=/var/log/rsync_client.log

    #rsync
    rsync_server="xxx.xxx.xxx.xxx

    xxx.xxx.xxx.xxx"

    rsync_user=pk10
    rsync_pwd=/etc/rsync_client.pwd
    rsync_module=module_pk10
    INOTIFY_EXCLUDE='(.*/*.log|.*/*.swp)$'
    RSYNC_EXCLUDE='/etc/rsyncd.d/rsync_exclude.lst'

    #rsync client pwd check
    if [ ! -e ${rsync_pwd} ];then
        echo -e "rsync client passwod file ${rsync_pwd} does not exist!"
        exit 0
    fi
    #inotify_function
    inotify_fun(){
        /usr/bin/inotifywait -mrq --timefmt '%Y/%m/%d-%H:%M:%S' --format '%T %w %f'
              --exclude ${INOTIFY_EXCLUDE}  -e modify,delete,create,move,attrib ${source_path}
              | while read file
          do
              for server in $rsync_server
              do
                  /usr/bin/rsync -auvrtzopgP --delete --exclude-from=${RSYNC_EXCLUDE} --progress --bwlimit=200 --password-file=${rsync_pwd} ${source_path} ${rsync_user}@${server}::${rsync_module}
              done
          done
    }
    #inotify log
    inotify_fun >> ${log_file} 2>&1 &

    参考:http://seanlook.com/2014/12/12/rsync_inotify_setup/

  • 相关阅读:
    git如何忽略文件或者文件夹
    jsonp跨域请求发布出去
    PHP
    curl保存图片
    curl 请求
    输入框纯数字
    PHP允许AJAX跨域请求的两种方法
    IOS开发笔记 IOS如何访问通讯录
    Android 蓝牙开发(整理大全)
    新的移动服务示例
  • 原文地址:https://www.cnblogs.com/zhaojonjon/p/7136703.html
Copyright © 2011-2022 走看看