
sersync类似于inotify,同样用于监控,但它克服了inotify的缺点.
inotify最大的不足是会产生重复事件,或者同一个目录下多个文件的操作会产生多个事件,例如,当监控目录中有5个文件时,删除目录时会产生6个监控事件,从而导致重复调用rsync命令。另外比如:vim文件时,inotify会监控到临时文件的事件,但这些事件相对于rsync来说是不应该被监控的
sersync 优点:
https://code.google.com/archive/p/sersync/
sersync下载地址:
https://code.google.com/archive/p/sersync/downloads
[root@backup-server ~]#dnf -y install rsync-daemon rsync
[root@backup-server ~]#vi /etc/rsyncd.conf
uid = root #提定以哪个用户来访问共享目录,将之指定为生成的文件所有者,默认为nobody
gid = root #默认为nobody
#port = 874 可指定非标准端口,默认873/tcp
#use chroot = no
max connections = 0
ignore errors
exclude = lost+found/
log file = /var/log/rsyncd.log
pid file = /var/run/rsyncd.pid
lock file = /var/run/rsyncd.lock
reverse lookup = no
[backup] #每个模块名对应一个不同的path目录,如果同名后面模块生效
path = /data/backup/
comment = backup dir
read only = no #默认是yes,即只读
auth users = rsyncuser #默认anonymous可以访问rsync服务器
secrets file = /etc/rsync.pas
[root@backup-server ~]#mkdir -pv /data/backup
[root@backup-server ~]#echo "rsyncuser:123456" > /etc/rsync.pas
[root@backup-server ~]#chmod 600 /etc/rsync.pas
[root@backup-server ~]#rsync --daemon
[root@backup-server ~]#systemctl start rsyncd
[root@data-centos8 ~]#wget https://storage.googleapis.com/google-code-archive-downloads/v2/code.google.com/sersync/sersync2.5.4_64bit_binary_stable_final.tar.
gz
[root@data-centos8 ~]#tar xf sersync2.5.4_64bit_binary_stable_final.tar.gz
[root@data-centos8 ~]#cp -a GNU-Linux-x86 /usr/local/sersync
[root@data-centos8 ~]#echo 'PATH=/usr/local/sersync:$PATH' >
/etc/profile.d/sersync.sh
[root@data-centos8 ~]#source /etc/profile.d/sersync.sh
[root@data-centos8 ~]#rpm -q rsync &> /dev/null || dnf -y install rsync
[root@data-centos8 ~]#cp /usr/local/sersync/confxml.xml{,.bak}
[root@data-centos8 ~]#vim /usr/local/sersync/confxml.xml
# 是否开启调试模式 #不开启文件过滤功能,当为true时,以下类型的文件将不同
步 # 监控事件,默认监控
delete/close_write/moved_from/moved_to/create folder #修改此行为true,文件属性变化后也会同步 # rsync命令的配置段 #修改此行,需要同步的源目录或文件,建议同步目
录 #修改此行,指定备份服务器地址和rsync
daemon的模块名,如果下面开启了ssh start,此时name为远程shell方式运行时的目标目录 # 指定rsync选项 #修
改此行为true,指定备份服务器的rsync配置的用户和密码文件 #指定rsync的非
标准端口号 #默认使用rsync daemon运行rsync命令,true为使用远程shell模
式 #错误重传及日志文件路径 #不开启crontab功能 #不开启crontab定时传输的筛选功能 #####################################以下行不需要修改
####################################
[root@data-centos8 ~]#echo 123456 > /etc/rsync.pas[root@data-centos8 ~]#chmod 600 /etc/rsync.pas
[root@data-centos8 ~]#sersync2 -dro /usr/local/sersync/confxml.xml
set the system param
execute:echo 50000000 > /proc/sys/fs/inotify/max_user_watches
execute:echo 327679 > /proc/sys/fs/inotify/max_queued_events
parse the command param
option: -d run as a daemon
option: -r rsync all the local files to the remote servers before the sersync work
option: -o config xml name: /usr/local/sersync/confxml.xml
daemon thread num: 10
parse xml config file
host ip : localhost host port: 8008
daemon start,sersync run behind the console
use rsync password-file :
user is rsyncuser
passwordfile is /etc/rsync.pas
config xml parse success
please set /etc/rsyncd.conf max connections=0 Manually
sersync working thread 12 = 1(primary thread) + 1(fail retry thread) + 10(daemon sub threads)
Max threads numbers is: 22 = 12(Thread pool nums) + 10(Sub threads)
please according your cpu ,use -n param to adjust the cpu rate
------------------------------------------
rsync the directory recursivly to the remote servers once
working please wait...
execute command: cd /data/www && rsync -artuz -R --delete ./ rsyncuser@192.168.100.38::backup --password-file=/etc/rsync.pas >/dev/null 2>&1
run the sersync:
watch path is: /data/www

