Rsync+Lsync实时同步

实验环境
系统:Cents 7.2
源主机:192.168.1.1
目标主机:192.168.1.2
两台主机都安装了httpd

在源主机上配置(192.168.1.1)

yum -y install rsync
systemctl start rsync
systemctl enable rsync
vi /etc/rsync_exclude.lst     # 指定要排除复制的文件或目录
test
test.txt

在目标主机上配置(192.168.1.2)

yum -y install rsync
vim /etc/rsyncd.conf
[backup]
path = /var/www/html
hosts allow = 192.168.1.1
hosts deny = * 
list = true 
uid = root 
gid = root
read = only = false
:wq!

systemctl start rsyncd
systemctl enable rsyncd

在源主机上测试同步(192.168.1.1)

touch /var/www/thml/index.html
rsync -avz --delete (--exclude-from=/etc/rsync_exclude.lst(不备份的))  /var/www/html/ 192.168.1.2::backup
# 设置定时任务
[root@linuxprobe ~]# crontab -e
# 每天凌晨两点钟备份一次
00 02 * * * rsync -avz --delete --exclude-from=/etc/rsync_exclude.lst /root/work/ 192.168.1.2::backup

Lsync+Rsync

源主机上配置(192.168.1.1)
yum -y install epel-release
yum -y install lsyncd
vim /etc/lsyncd
注释掉第8行
添加以下内容settings{
----
-- User configuration file for lsyncd.
--
-- Simple example for default rsync, but executing moves through on the target.
--
-- For more examples, see /usr/share/doc/lsyncd*/examples/
--
-- sync{default.rsyncssh, source="/var/www/html", host="localhost", targetdir="/tmp/htmlcopy/"}
settings{
    logfile      ="/var/log/lsyncd.log",
    statusFile = "/tmp/lsyncd.stat",
    inotifyMode  = "CloseWrite",
    maxProcesses = 7,
    statusInterval = 1,
    -- nodaemon =true,
}
sync{
    default.rsync,
    -- source directory
    source="/var/www/html/",

    -- destination Hostname or IP address:(the name set in rsyncd.conf)
    target="192.168.1.2::backup",
    -- excluding list
    -- excludeFrom="/etc/rsync_exclude.lst",
   rsync     = {
        binary    = "/usr/bin/rsync",
        archive   = true,
        compress  = true,
        verbose   = true
        }
}
wq!

systemctl start lsyncd
systemctl status lsyncd   先确认lsyncd的运行状态
systemctl enable lsyncd

你可能感兴趣的:(Rsync+Lsync实时同步)