lsyncd 简介 Lsyncd功能跟Inotify和Sersync相同,属于实时同步工具,但是Lsyncd功能更加强大,Lysncd 实际上是lua语言封装了 inotify 和 rsync 工具,采用了 Linux 内核 *(2.6.13 及以后)里的 inotify 触发机制,然后通过rsync去差异同步,达到实时的效果。Lsyncd最强大之处在于简单高效传输海量数据并且Lsyncd支持多种工作模式。
github 项目地址:https://github.com/lsyncd/lsyncd
yum install -y epel-release
yum clean all
yum makecache
yum install lsyncd -y
准备密码文件
cat > /etc/rsync_passwd <<EOF
Nginx@2025
chmod 600 /etc/rsync_passwdlsyncd配置文件
服务器启动后 lsyncd服务器上的/tmp下的文件就会同步到rsync服务器端的/backup下,但是同步仅限于在bash交互式操作下的文件同步。
cat /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",
target = "rsync_backup@10.0.0.7::backup",##rsync_backup定义同步的用户、服务器和同步目录
delete = true,
exclude = { ".*" },
delay = 1,
rsync = {
binary = "/usr/bin/rsync",
archive = true,
compress = true,
verbose = true,
password_file = "/etc/rsync_passwd",#之前定义的密码文件
_extra = {"--bwlimit=200"}
}
}
systemctl start lsyncd
systemctl status lsyncdyum install rsync -y
cat > /etc/rsyncd.conf << 'EOF'
uid = www
gid = www
port = 873
fake super = yes
use chroot = no
max connections = 200
timeout = 600
ignore errors
read only = false
list = false
auth users = rsync_backup
secrets file = /etc/rsync.passwd
log file = /var/log/rsyncd.log
[backup]
comment = this is a backup dir,to website data.
path = /backup
[data]
comment = this is secord backup dir,to website data..
path = /data
EOF
useradd -u 1000 -M -s /sbin/nologin www
chown -R www:www /{backup,data}
cat > /etc/rsync.passwd << EOF
rsync_backup:Nginx@2025
EOF
chmod 600 /etc/rsync.passwd
systemctl start rsyncd
systemctl enable rsyncd
nginx: access_log syslog:server=192.168.20.209,facility=local6 aka_logs;
日志端:
grep -Ev '^$|#' /etc/rsyslog.conf
$ModLoad imudp
$UDPServerRun 514
$ModLoad imtcp
$InputTCPServerRun 514
$WorkDirectory /var/lib/rsyslog
$IncludeConfig /etc/rsyslog.d/*.conf
$OmitLocalLogging on
$IMJournalStateFile imjournal.state
*.info;mail.none;authpriv.none;cron.none /var/log/messages
authpriv.* /var/log/secure
mail.* -/var/log/maillog
cron.* /var/log/cron
*.emerg :omusrmsg:*
uucp,news.crit /var/log/spooler
local7.* /var/log/boot.log
local6.* /var/log/mk-nginx/access.log
systemctl restart rsyslog
systemctl enable rsyslog