一,查看本地centos的版本:
[root@localhost lib]# cat /etc/redhat-release
CentOS Linux release 8.1.1911 (Core)
说明:作者:刘宏缔 邮箱: 371125307@qq.com
二,查看内核是否支持inotify
[root@localhost nfs]# ll /proc/sys/fs/inotify/总用量0
-rw-r--r-- 1 root root 0 2月 24 15:01max_queued_events-rw-r--r-- 1 root root 0 2月 24 15:01max_user_instances-rw-r--r-- 1 root root 0 2月 24 13:20 max_user_watches
说明:看到列出的三个文件,说明系统内核支持inotify
说明:sersync是基于inotify的,所以需要这个功能模块的支持
三,配置inotify参数,避免因限制导致出错
查看inotify相关的三个值:
分别为:队列中event的长度,用户可监控数量的多少,用户可使用的实例数量
[root@localhost nfs]# sysctl -a | grepmax_queued_events
fs.inotify.max_queued_events= 16384[root@localhost nfs]# sysctl-a | grepmax_user_watches
fs.inotify.max_user_watches= 8192[root@localhost nfs]# sysctl-a | grepmax_user_instances
fs.inotify.max_user_instances= 128
修改:
[root@localhost source]# sysctl -w fs.inotify.max_queued_events="327679"fs.inotify.max_queued_events= 327679[root@localhost source]# sysctl-w fs.inotify.max_user_watches="50000000"fs.inotify.max_user_watches= 50000000[root@localhost source]# sysctl-w fs.inotify.max_user_instances="65535"fs.inotify.max_user_instances= 65535[root@localhost source]# sysctl-p
四,下载安装sersync
1,下载地址
说明:官方地址:
https://sersync.googlecode.com/files/sersync2.5.4_64bit_binary_stable_final.tar.gz
在墙外打不开,大家可以访问下面github上面的地址:
https://github.com/wsgzao/sersync
2,下载及解压:
[root@localhost source]# wget https://codeload.github.com/wsgzao/sersync/zip/master
[root@localhost source]# mv master master.zip[root@localhost source]#unzip master.zip
3,安装到soft目录
[root@localhost source]# cd sersync-master/[root@localhost sersync-master]# lsinotify-tools-3.14.tar.gz README.md rsync-3.1.1.tar.gz sersync2.5.4_64bit_binary_stable_final.tar.gz
[root@localhost sersync-master]# tar -zxvf sersync2.5.4_64bit_binary_stable_final.tar.gz
[root@localhost sersync-master]# mv GNU-Linux-x86/ /usr/local/soft/sersync2
五,查看sersync的帮助信息
[root@localhost sersync-master]# /usr/local/soft/sersync2/sersync2 -help
六,sersync的参数说明:
参数-d:启用守护进程模式
参数-r:在监控前,将监控目录与远程主机用rsync命令推送一遍
参数-n: 指定开启守护线程的数量,默认为10个
参数-o:指定配置文件,默认使用confxml.xml文件
七,sersync的配置:
1,inotify项的配置建议:说明:是使用inotify监控的类型:
2,localpath:
说明:
/data/nfs/source是本地要监控的目录
remote 对应服务的ip和name
3,rsync的配置
4,说明:其他的设置项不必改动
八,运行sersync
[root@localhost liuhongdi]# /usr/local/soft/sersync2/sersync2 -r -d -o /usr/local/soft/sersync2/confxml.xml
九,关于rsync服务的搭建:参见这一篇:
https://www.cnblogs.com/architectforest/p/12360875.html
十,sersync的日志位于何处?
[root@localhost liuhongdi]# more /tmp/rsync_fail_log.sh#errno2560cd/data/nfs/source && rsync -artuz -R "./abc.txt" pusher@127.0.0.1::wwwroot --password-file=/data/rsync/conf/client.pass >/dev/null 2>&1
十一,测试本地两个目录的同步情况:
1, /data/nfs/source这个目录是sersync监控的目录
[root@localhost source]# pwd
/data/nfs/source
[root@localhost source]#virand.txt
[root@localhost source]#morerand.txt
rand
2,/data/nfs/dest 是rsync服务中wwwroot这个区域指定的目录
[root@localhost dest]# pwd
/data/nfs/dest
[root@localhost dest]#morerand.txt
rand
说明:在监控目录中增加文件后,rsync同步的目录中文件也立即出现,且内容相同
所以sersync很适合做文件备份