• 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/

  • 相关阅读:
    IDEA手动创建JFinal项目(404问题处理)
    php 把数字1-1亿换成汉字表述,例如 150 转成 一百五十
    模仿console自写函数打印js的对象
    每瓶啤酒2元,2个空酒瓶或4个瓶盖可换1瓶啤酒。10元最多可喝多少瓶啤酒? php
    js-Event构造函数,也许你需要
    js将金额专成每隔3位数加逗号
    js-PC版监听键盘大小写事件
    用php脚本给html中引用的js和css路径打上版本
    通过js的console优雅的将php调试信息输出
    android中加载的html获取的宽高不正确
  • 原文地址:https://www.cnblogs.com/zhaojonjon/p/7136703.html
Copyright © 2020-2023  润新知