1. 安装:
    yum -y install rsync inotify-tools
  2. rsync配置:
    1. 服务端:
      1. 配置文件:
        vim /etc/rsyncd.conf
        motd file = /etc/rsyncd.motd
        transfer logging = yes
        log file = /var/log/rsyncd.log
        port = 873
        address = xx.xx.xx.xx
        uid = root
        gid = root
        use chroot = no
        read only = no
        max connections = 10
        [common]
        comment = rsync lee
        path = /path/to/dir
        ignore errors
        auth users = test_user
        secrets file = /etc/rsyncd.secrets
        hosts allow = xx.xx.xx.xx/255.255.255.0
        hosts deny = *
        list = false
      2. 创建用户密码:
        echo  "test_user:test_pass"  >  /etc/rsyncd.secrets
        chmod  600  /etc/rsyncd.secrets
      3. 创建提示信息文件:
        echo "some message" > /etc/rsyncd.motd
      4. 启动服务:
        rsync --daemon
    2. 客户端:
      创建密码文件(免输入密码):
      echo  "test_pass"  >  /root/passwd
      chmod  600  /root/passwd
  3. 写监控脚本:
    vim auto_rsync.sh
    #!/bin/bash
    while inotifywait -rq -e modify,create,move,delete,attrib /path/to/dir  &>  /dev/null ; do
     rsync -avz /path/to/dir --password-file=/etc/rsyncd.secrets test_user@xx.xx.xx.xx::common  &>  /dev/null
    done &
  4. 运行:
    chmod  +x  test.sh
    ./test.sh
文档更新时间: 2020-08-08 20:40   作者:lee