rsync+lsyncd實現實時同步


1.接收端安裝rsync,修改/etc/rsyncd.conf配置文件,然后啟動服務。

uid = root
gid = root
use chroot = no
max connection = 4
secrets file = /etc/rsyncd.secrets

[test] path
= /tmp/test auth users = bak read only = no

2.發送端安裝rsync+lsyncd,修改/etc/lsyncd.conf配置文件,編輯密碼文件(如果使用了密碼同步),然后啟動lsyncd服務。

settings = {
logfile = "/var/log/lsyncd.log",
statusFile = "/tmp/lsyncd.stat",
statusInterval = 1,  -- 同步時間間隔
}

sync {
default.rsync,
source="/data0/test",
target="bak@172.16.225.222::test",

rsync = {
        binary = "/usr/bin/rsync",
        archive = true,
        compress = true,
        verbose   = true,
        --delete =  true,
         _extra = {"--password-file=/etc/rsyncd.secrets"},
        },
}

3.在發送端要同步的目錄中添加、刪除文件,查看接收端是否同步。

4.配置lsyncd日志文件輪轉,防止日志文件太大

修改/etc/logrotate.d/lsyncd配置文件

/var/log/lsyncd/*log { 
    missingok 
    notifempty 
    sharedscripts 
    postrotate 
        /etc/rc.d/init.d/lsyncd restart 2>&1 > /dev/null || true 
    endscript 
}

 

參考:http://openlinuxfly.blog.51cto.com/7120723/1679279https://github.com/axkibe/lsyncd/blob/master/default-rsync.lua

如果使用rsync+Inotify-tools方式可參考:

http://www.osyunwei.com/archives/7435.html

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM