1. 安装:
    # 服务端
    yum  -y  install  rsync
    # 客户端
    yum  -y  install  rsync  inotify-tools
  2. 服务端(启动 rsync 服务):
    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
  3. 客户端(将文件同步到服务端):
    1. 创建密码文件(免输入密码):
      echo  "test_pass"  >  /root/passwd
      chmod  600  /root/passwd
    2. 写监控脚本:
      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 &
    3. 运行:
      chmod  +x  test.sh
      ./test.sh
文档更新时间: 2020-11-22 20:37   作者:lee