再测试一下rsync+inotify-tools
系统文件解释
root@node2:/home/admin# ls -l /proc/sys/fs/inotify/
total 0
-rw-r--r-- 1 root root 0 Dec 23 19:45 max_queued_events
-rw-r--r-- 1 root root 0 Dec 23 19:31 max_user_instances
-rw-r--r-- 1 root root 0 Dec 23 19:31 max_user_watches
max_user_watches: 设置inotifywait或inotifywatch命令可以监视的文件数量(单进程)
默认只能监控8192个文件
max_user_instances: 设置每个用户可以运行的inotifywait或inotifywatch命令的进程数
默认每个用户可以开启inotify服务128个进程
max_queued_events: 设置inotify实例事件(event)队列可容纳的事件数量
默认监控事件队列长度为16384
客户端:远端服务器
配置文件
root@node3:/home/admin# cat /etc/rsyncd.conf
# rsync用户
uid = rsync
gid = rsync
use chroot = no
max connections = 200
timeout = 300
pid file = /var/run/rsyncd.pid
lock file = /var/run/rsync.lock
log file = /var/log/rsyncd.log
ignore errors
read only = false
list = false
hosts allow = 10.1.0.0/24
hosts deny = 0.0.0.0/32
# 远端用户
auth users = admin
secrets file = /etc/rsync.password
[backup]
comment = "backup dir "
path = /backup
root@node3:/home/admin# useradd -s /sbin/nologin -M rsync
root@node3:/home/admin# echo "admin:passwd">/etc/rsync.password #可以ssh的admin用户及密码
root@node3:/home/admin# chmod 600 /etc/rsync.password
root@node3:/home/admin# rsync --daemon
服务端:同步文件过去
root@node2:~# echo "passwd" >>/etc/rsync.password #admin用户的密码
root@node2:~# chmod 600 /etc/rsync.password
测试免密传输
root@node2:~# rsync -avzP --delete /etc/hosts admin@10.1.0.130::backup --password-file=/etc/rsync.password
测试参考脚本
root@node2:~# cat test_inotify.sh
#!/bin/bash
path=/root/rsync-test
backup_server=10.1.0.130
export RSYNC_PASSWORD=adminadmin
/usr/bin/inotifywait -mrq -e modify,delete,create,attrib,move /root/rsync-test | while read line
do
echo ${line}
rsync -az --delete /root/rsync-test/ admin@${backup_server}::backup
done
# 验证
root@node2:~# touch rsync-test/file1
root@node2:~# bash test_inotify.sh
/root/rsync-test/ ATTRIB file1
root@node3:/home/admin# ls /backup/
file1