lsync+rsync 实时同步配置说明

服务端(接收日志端)

  • 安装rsync+xinetd
yum -y install xinetd rsync  
  • 开启rsync守护进程
vim /etc/xinetd.d/rsync

service rsync  
{
    disable = yes
    flags       = IPv4
    socket_type     = stream
    wait            = no
    user            = root
    server          = /usr/bin/rsync
    server_args     = --daemon
    log_on_failure  += USERID
}
  • 修改后启动服务并添加开机自启动
service xinetd start  
chkconfig xinetd on  
  • 配置同步路径
uid = root  
gid = root  
port = 873  
fake super = yes  
use chroot = no  
max connections = 2000  
timeout = 600  
ignore errors  
read only = false  
list = false  
#auth users = rsync_backup
#secrets file = /etc/rsync.password
log file = /data/logs/rsyncd.log

[sgame_logs]
comment = welcome to sgame logs  
path = /data/rsync/myproj  
  • 以daemon模式启动rsync
/usr/bin/rsync --daemon

推送端(lsync同步客户端)

  • 安装epel源和lsyncd
wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-6.repo  
yum install lsyncd rsync  
  • 配置lsyncd.conf
vim /etc/sysconfig/lsyncd

settings {  
   --pidfile = "/var/run/lsyncd.pid",
   --nodaemon   = false,
   inotifyMode = "CloseWrite",
   maxProcesses = 8,
   statusFile = "/tmp/lsyncd.status",
   statusInterval = 1,
   logfile = "/var/log/lsyncd/lsyncd.log"
}



sync {  
    default.rsync,
    source    = "/data/myproj_sgame_logs",
    target    = "10.1.18.13::sgame_logs",
    delete="running",
--    excludeFrom = "/etc/rsync_exclude.lst",
    delay = 5,
    init = false,
    rsync     = {
        binary = "/usr/bin/rsync",
        perms = true,
        acls = true,
        xattrs = true,
        links = true,
        quiet = true,
        archive = true,
        compress = true,
        verbose   = true,
        --password_file = "/etc/rsync.pwd",
        _extra    = {"--bwlimit=2000"}
        }
    }
  • 手动测试同步配置是否正常
rsync -avz --delete /data/myproj_sgame_logs/ 10.1.18.13::sgame_logs  
  • sysctl优化 修改默认监控的文件数(腾讯云默认是20000)
fs.inotify.max_user_watches = 2001192  
  • 启动lsyncd服务
lsyncd -pidfile /var/run/lsyncd.pid /etc/sysconfig/lsyncd  
  • 查看启动服务状态
ps aux|grep lsyncd  
/etc/init.d/lsyncd status
  • 放行防火墙端口 873(rsync默认端口), 在客户端源目录增加修改文件,测试同步效果