lsyncd

目录

功能介绍

Lsyncd 是lua语言封装了 inotify 和 rsync 工具,采用了 Linux 内核(2.6.13 及以后)里的 inotify 触发机制,然后通过rsync去差异同步,达到实时的效果。它最令人称道的特性是,完美解决了 inotify + rsync海量文件同步带来的文件频繁发送文件列表的问题 —— 通过时间延迟或累计触发事件次数实现。另外,它的配置方式很简单,lua本身就是一种配置语言,可读性非常强。lsyncd也有多种工作模式可以选择,本地目录cp,本地目录rsync,远程目录rsyncssh。

安装配置

系统:centos 7

# 机器全部要安装rsync
yum install rsync

# 文件源服务器需要免密登陆目的服务器
ssh-keygen
ssh-copy-id root@destination

# 安装
yum install lsyncd

# 配置文件为 /etc/lsyncd.conf,需注释默认配置文件的最后一行
# 配置文件注释需要使用 --

settings {
       logfile = "/var/log/lsyncd/lsyncd.log",
       statusFile = "/var/log/lsyncd/lsyncd.status",
       inotifyMode = "CloseWrite",
       maxProcesses = 8,
       }
# I. 本地目录同步directcp/rm/mv 适用500+万文件变动不大
sync {
     default.direct,
     source = "/tmp/src",
     target = "/tmp/dest",
     delay = 1
     maxProcesses = 1
     }
# II. 本地目录同步rsync模式rsync
sync {
     default.rsync,
     source = "/tmp/src",
     target = "/tmp/dest1",
     excludeFrom = "/etc/rsyncd.d/rsync_exclude.lst",
     rsync = {
             binary = "/usr/bin/rsync",
             archive = true,
             compress = true,
             bwlimit = 2000
             }
     }
# III. 远程目录同步rsync模式 + rsyncd daemon
sync {
     default.rsync,
     source = "/tmp/src",
     target = "syncuser@10.4.7.10::module1",
     delete="running",
     exclude = { ".*", ".tmp" },
     delay = 30,
     init = false,
     rsync = {
             binary = "/usr/bin/rsync",
             archive = true,
             compress = true,
             verbose = true,
             password_file = "/etc/rsyncd.d/rsync.pwd",
             _extra = {"--bwlimit=200"}
             }
     }
# IV. 远程目录同步rsync模式 + ssh shell
sync {
     default.rsync,
     source = "/tmp/src",
     target = "10.4.7.10:/tmp/dest",
     # target = "root@10.4.7.10:/remote/dest",
     # 上面target注意如果是普通用户必须拥有写权限
     maxDelays = 5,
     delay = 30,
     # init = true,
     rsync = {
             binary = "/usr/bin/rsync",
             archive = true,
             compress = true,
             bwlimit = 2000
             # rsh = "/usr/bin/ssh -p 22 -o StrictHostKeyChecking=no"
             # 如果要指定其它端口请用上面的rsh
     }
}
# V. 远程目录同步rsync模式 + rsyncssh效果与上面相同
sync {
     default.rsyncssh,
     source = "/tmp/src2",
     host = "10.4.7.10",
     targetdir = "/remote/dir",
     excludeFrom = "/etc/rsyncd.d/rsync_exclude.lst",
     # maxDelays = 5,
     delay = 0,
     # init = false,
     rsync = {
             binary = "/usr/bin/rsync",
             archive = true,
             compress = true,
             verbose = true,
             _extra = {"--bwlimit=2000"},
     },
     ssh = {
            port = 1234
     }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值