安装lsyncd

 root@mysql-2:~# apt-get  install -y lsyncd

整理需要同步的服务器

debian 安装配置lsyncd

整理配置文件

  root@mysql-2:/data/lsyncd# cat /etc/lsyncd.conf 
  settings {
      logfile ="/data/mysql/project_nginx.log",
      statusFile ="/data/lsyncd/lsyncd.status",
      inotifyMode = "CloseWrite",
      maxProcesses = 8,
      -- maxConnections = 4,
      -- delay = 10,
      -- excludeFrom = file,
      -- excludeFrom 排除选项
      }
  sync {
      default.rsyncssh,
      source    = "/data/docker-compose",
      host      = "192.168.1.23",
      targetdir = "/data/docker-compose",
      -- exclude = "/data/www/public_html/config.inc.php",  #排除此文件不同步
      -- maxDelays = 5,累计到多少所监控的事件激活一次同步,即使后面的delay延迟时间还未到
      -- delay = 2,
      -- init = false,这是一个优化选项,当init = false,只同步进程启动以后发生改动事件的文件,原有的目录即使有差异也不会同步。默认是true
      rsync    = {
          binary = "/usr/bin/rsync",
          archive = true,
          compress = true,
          verbose   = true,
          -- _extra = {"--bwlimit=2000"},
          },
      ssh  = {
          binary = "/usr/bin/ssh",
          port  =  22,
          }
      }
  sync {
      default.rsyncssh,
      source    = "/data/docker-compose",   #源目录
      host      = "192.168.1.43",
      targetdir = "/data/docker-compose",   #目标目录
      -- exclude = "/data/www/public_html/config.inc.php",
      -- maxDelays = 5,累计到多少所监控的事件激活一次同步,即使后面的delay延迟时间还未到
      -- delay = 2,
      -- init = false,这是一个优化选项,当init = false,只同步进程启动以后发生改动事件的文件,原有的目录即使有差异也不会同步。默认是true
      rsync    = {
          binary = "/usr/bin/rsync",
          archive = true,
          compress = true,
          verbose   = true,
          -- _extra = {"--bwlimit=2000"},
          },
      ssh  = {
          binary = "/usr/bin/ssh",
          port  =  22,
          }
      }

启动测试

  root@mysql-2:/data/lsyncd# lsyncd /etc/lsyncd.conf

测试

 目录里面有问题或者新建立都会同步,注意没有目录会自己创建目录同步