当前位置: 首页 > 工具软件 > lsyncd > 使用案例 >

lsyncd和rsync实现文件实时同步

邵伟
2023-12-01

环境要求:

源主机和目的主机都要安装rsync,需要检测文件变化的主机安装lsyncd

rsync安装方式:

yum install epel-release -y && yum install rsync -y

lsyncd安装方式:

yum install epel-release -y && yum install lsyncd -y

软件说明:

rsync 用于同步文件

lsyncd 用于监控文件变化

配置说明:

目的主机需要开启rsync,并采用后台守护方式进行启动

rsync配置:

  uid = root
  gid = root
  use chroot = no
  max connections = 20
  pid file = /var/run/rsyncd.pid
  log file = /var/log/rsync.log
  lock file = /var/run/rsyncd.lock
  exclude = lost+found/
  reverse lookup = no
  timeout = 900
  dont compress   = *.gz *.tgz *.zip *.z *.Z *.rpm *.deb *.bz2
  
  [jenkins]
    path = /data/jenkins/
    read only = no
    auth users = ysrd_backup
    secrets file = /etc/rsyncd.password
    list = no
 

秘钥文件注意点:

格式:账号:密码

文件权限:600

echo '账号:密码' > /etc/rsyncd.password && chmod 600 /etc/rsyncd.password

启动命令:

systemctl start rsyncd

systemctl enable rsyncd

lsyncd配置:

settings {


    logfile = "/var/log/lsyncd/lsyncd.log",
    pidfile = "/var/run/lsyncd.pid",
    statusFile = "/var/log/lsyncd/lsyncd.status",
    statusInterval = 5,
    nodaemon = false,
    inotifyMode = "CloseWrite or Modify",
    maxProcesses = 5,
    maxDelays = 1,
    inist = ture,


}


sync {
    default.rsync,
    source = "/home/jenkins/",
    target = "backup_username@xx.xx.xx.xx::jenkins",
    exclude = { "workspace/**", "logs/**" },
    delay = 3,
    rsync = {
        binary = "/usr/bin/rsync",
        archive = true,
        compress = true,
        verbose = true,
        password_file = "/etc/rsync.password",
    }


}

秘钥文件注意点:

格式:账号:密码

文件权限:600

echo '密码' > /etc/rsync.password && chmod 600 /etc/rsync.password

启动命令:

systemctl start rsyncd

systemctl enable rsyncd

注意:云主机rsync需要开通873端口

双向同步:

两边各自配置rsync和lsync即可,等单向同步结束后再进行配置

 类似资料: