lsyncd-实时同步(镜像)守护程序

E-mail: [email protected]

官方文档

https://axkibe.github.io/lsyncd/
https://github.com/axkibe/lsyncd

简介

Lsyncd使用文件系统事件接口(inotify或fsevents)来监视对本地文件和目录的更改。Lsyncd将这些事件整理几秒钟,然后生成一个或多个进程以将更改同步到远程文件系统。默认同步方法是rsync
Lsyncd是一种轻量级的实时镜像解决方案。Lsyncd相对容易安装,不需要新的文件系统或块设备。Lysncd不会妨碍本地文件系统性能

可以通过配置文件实现细粒度的自定义。自定义操作配置甚至可以从头开始编写,从shell脚本到用Lua语言编写的代码

版本要求

Lsyncd 2.2.1要求所有源和目标计算机上的rsync> = 3.1

安装

lsyncd 在 epel源中

yum install lsyncd

配置

配置文件说明 /etc/lsyncd.conf
lsyncd配置文件使用lua语法编写

settings
settings {
logfile    日志文件
pidfile    pid文件
nodaemon   表示不启用守护模式,默认
statusFile   运行状态文件
statusInterval   将lsyncd的状态写入上面的statusFile的间隔,默认10秒
inotifyMode     指定inotify监控的事件,默认是CloseWrite,还可以是Modify或CloseWrite or Modify
maxProcesses    最大进程数
maxDelays     累计多少监控事件同步一次,即使delay时间未到也同步
}

sync 三种模式

default.rsync

sync {
 default.rsync,
 source = "/tmp/src",
 target = "172.29.88.223:/tmp/dest",
 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"
}
}

rsync daemon

sync {
 default.rsync,
 source = "/tmp/src",
 target = "[email protected]::backup",
 delete="running",
 exclude = { ".*", ".tmp" },
 delay = 3,
 init = false,
rsync = {
 binary = "/usr/bin/rsync",
 archive = true,
 compress = true,
 verbose = true,
 password_file = "/etc/rsync.pwd",
 _extra = {"--bwlimit=200"}
}
}

default.rsyncssh

sync {
   default.rsyncssh,
   source="/srcdir",
   host="remotehost",
   excludeFrom="/etc/lsyncd.exclude",
   targetdir="/dstdir",
   rsync = {
     archive = true,
     compress = false,
     whole_file = false
   },
   ssh = {
     port = 1234
   }
}

default.direct

sync {
    default.direct,
    source  = "/home/user/src/",
    target  = "/home/user/trg/"
}

/etc/lsyncd.conf

settings {
 logfile = "/var/log/lsyncd/lsyncd.log",
 statusFile = "/var/log/lsyncd/lsyncd.status",
 inotifyMode = "CloseWrite",
 maxProcesses = 8,
}
sync {
 default.rsync,
 source = "/tmp/src",
 target = "[email protected]::backup",
 delete="running",
 exclude = { ".*", ".tmp" },
 delay = 3,
 init = false,
rsync = {
 binary = "/usr/bin/rsync",
 archive = true,
 compress = true,
 verbose = true,
 password_file = "/etc/rsync.pwd",
 _extra = {"--bwlimit=200"}
}
}
sync {
 default.rsync,
 source = "/tmp/src",
 target = "[email protected]::wuxing",
 delete="running",
 exclude = { ".*", ".tmp" },
 delay = 3,
 init = false,
rsync = {
 binary = "/usr/bin/rsync",
 archive = true,
 compress = true,
 verbose = true,
 password_file = "/etc/rsync.pwd",
 _extra = {"--bwlimit=200"}
}
}

delete

delete	=	true       #在目标上删除源中没有的内容。在启动时以及在正常操作期间删除的内容
delete	=	false      #不会删除目标上的任何文件。不在启动时也不在正常操作上
delete	=	'startup'  # Lsyncd将在启动时删除目标上的文件,但不会在正常操作时删除
delete	=	'running'  # Lsyncd在启动时不会删除目标上的文件,但会删除正常操作期间删除的文件
settings {
 logfile = "/var/log/lsyncd/lsyncd.log",
 statusFile = "/var/log/lsyncd/lsyncd.status",
 inotifyMode = "CloseWrite",
 maxProcesses = 8,
}
sync {
 default.rsync,
 source = "/data",
 target = "rsync_backup@backup::backup",
 delete= true,
 exclude = { ".*" },
 delay = 1,
rsync = {
 binary = "/usr/bin/rsync",
 archive = true,
 compress = true,
 verbose = true,
 password_file = "/etc/rsync.pwd",
 _extra = {"--bwlimit=200"}
}
}

你可能感兴趣的:(存储)