sersync 介绍
sersync类似于inotify,同样用于监控,但它克服了inotify的缺点.
inotify最大的不足是会产生重复事件,或者同一个目录下多个文件的操作会产生多个事件,例如,当监
控目录中有5个文件时,删除目录时会产生6个监控事件,从而导致重复调用rsync命令。另外比如:vim
文件时,inotify会监控到临时文件的事件,但这些事件相对于rsync来说是不应该被监控的
sersync 优点:
sersync是使用c++编写,而且对linux系统文件系统产生的临时文件和重复的文件操作进行过滤,
所以在结合rsync同步的时候,节省了运行时耗和网络资源。因此更快。
sersync配置很简单,其中提供了静态编译好的二进制文件和xml配置文件,直接使用即可
sersync使用多线程进行同步,尤其在同步较大文件时,能够保证多个服务器实时保持同步状态
sersync有出错处理机制,通过失败队列对出错的文件重新同步,如果仍旧失败,则按设定时长对
同步失败的文件重新同步
sersync不仅可以实现实时同步,另外还自带crontab功能,只需在xml配置文件中开启,即也可以
按要求隔一段时间整体同步一次,而无需再额外配置crontab功能
sersync 可以二次开发
sersync项目地址: https://code.google.com/archive/p/sersync/
sersync下载地址:https://code.google.com/archive/p/sersync/downloads
案例:基于rsync daemon 实现 sersync
#在数据服务器上下载sersync,并拷贝至相应的目录,设置PATH变量
[root@sz-kx-centos8 ~]# wget https://raw.githubusercontent.com/orangle/sersync/master/release/sersync2.5.4_64bit_binary_stable_final.tar.gz
# 解压
[root@sz-kx-centos8 ~]# tar xf sersync2.5.4_64bit_binary_stable_final.tar.gz
[root@sz-kx-centos8 ~]# cp -a GNU-Linux-x86 /usr/local/sersync
[root@sz-kx-centos8 ~]# echo 'PATH=/usr/local/sersync:$PATH' > /etc/profile.d/sersync.sh
[root@sz-kx-centos8 ~]# source /etc/profile.d/sersync.sh
[root@sz-kx-centos8 ~]# ll /usr/local/sersync/
total 1772
-rwxr-xr-x 1 root root 2214 Oct 26 2011 confxml.xml
-rwxr-xr-x 1 root root 1810128 Oct 26 2011 sersync2
#确认安装rsync客户端工具
[root@sz-kx-centos8 ~]# rpm -q rsync &> /dev/null || dnf -y install rsync
#备份sersync配置文件
[root@sz-kx-centos8 ~]# cp /usr/local/sersync/confxml.xml{,.bak}
#修改sersync配置文件
[20:47:13 root@sz-kx-centos8 ~]# cat /usr/local/sersync/confxml.xml
<?xml version="1.0" encoding="ISO-8859-1"?>
<head version="2.5">
<host hostip="localhost" port="8008"></host>
<debug start="false"/>
<fileSystem xfs="false"/>
<filter start="false">
<exclude expression="(.*)\.svn"></exclude>
<exclude expression="(.*)\.gz"></exclude>
<exclude expression="^info/*"></exclude>
<exclude expression="^static/*"></exclude>
</filter>
<inotify>
<delete start="true"/>
<createFolder start="true"/>
<createFile start="false"/>
<closeWrite start="true"/>
<moveFrom start="true"/>
<moveTo start="true"/>
<attrib start="true"/> #修改此行为true,文件属性变化后也会同步
<modify start="false"/>
</inotify>
<sersync>
<localpath watch="/data/www"> #修改此行,需要同步的源目录或文件,建议同步目录
<remote ip="备份服务器IP" name="backup"/> #修改此行,指定备份服务器地址和rsync daemon的模块名,如果下面开启了ssh start,此时name为远程shell方式运行时的目标目录
<!--<remote ip="192.168.8.39" name="tongbu"/>-->
<!--<remote ip="192.168.8.40" name="tongbu"/>-->
</localpath>
<rsync>
<commonParams params="-a