sersync是基于inotify+rsync的大量文件的多服务器自动同步程序
使用 Linux 2.6 内核的 inotify 监控 Linux 文件系统事件,被监听目录下如果有文件发生修改,sersync 将通过内核自动捕获到事件,并将该文件利用 rsync 同步到多台远程服务器。sersync 仅仅同步发生增、删、改事件的单个文件或目录,不像rsync镜像同步那样需要比对双方服务器整个目录下数千万的文件,并且支持多线程同步,因此效率非常高。
sersync已不在更新,感谢sersync作者周洋
谷歌项目地址:https://code.google.com/archive/p/sersync/
上不去google的可以直接wget我本地的包,这里只提供64位版本的:http://down.whsir.com/downloads/sersync2.5.4_64bit_binary_stable_final.tar.gz
压缩包里面有两个文件confxml.xml sersync2
sersync2 这个是sersync主程序
confxml.xml 这个是sersync配置文件
配置文件部分常用参数解释:
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
?>
>
#保留字段,默认即可
#是否开启调试模式,默认false即可
#是否开启支持xfs文件系统,Centos7默认都是xfs的了,所以建议true开启
#是否开启过滤模式,根据需求开启,例:过滤以.php结尾的文件(.*)\.php
#过滤以.svn结尾的文件
#过滤以.gz结尾的文件
#过滤监控目录下的info路径
#过滤监控目录下的static路径
#过滤wwwroot/blogwhsir/目录下所有文件
>
#inotify监控事件
#如果不开启此项,在删除监控目录下的文件时,目标服务器的文件则不会同时删除,根据需求开启
#不开启不能监控子目录,建议true
#关闭提高通讯性能,默认就好
>
>
>
>
>
>
>
#指定要监控的本地目录
#指定要同步的目标服务器的IP地址,及目标服务器rsync的[模块]
>
>
>
#配置rsync
#rsync的参数
#是否开启rsync的认证模式,需要配置users及passwordfile,根据情况开启(如果开启,注意密码文件权限一定要是600)
#远程目标服务器的端口不是默认端口时使用
#是否开启rsync的超时时间
>
>
#目标服务器传输失败时会重新传输,再次失败会写入rsync_fail_log中,每隔一段时间(timeToExecute)执行脚本再次传输
#对监控目录与目标服务器每隔一段时间进行一次整体同步,默认600分钟,根据个人情况是否开启
#如果之前开启了文件过滤,这里也要设置过滤
>
>
>
>
>
>
#下面就是插件的设置(不做过多说明)
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
一个简单的演示示例:
确认当前系统关闭selinux及防火墙,或将873端口加入iptables白名单
我这里有两台centos6.7的主机,IP分别是192.168.0.70和192.168.0.31
我在192.168.0.70安装sersync,主动推送数据到192.168.0.31上
192.168.0.31上配置
安装创建rsync配置文件
|
1
|
rsync
|
|
1
|
conf
|
|
1
2
3
4
5
6
7
8
9
10
11
|
root
root
no
*
3
pid
lock
]
whsir
whsir
false
|
以守护进程方式启动rsync
|
1
|
daemon
|
192.168.0.70上配置
|
1
2
3
4
5
6
|
/
//down.whsir.com/downloads/sersync2.5.4_64bit_binary_stable_final.tar.gz
5.4_64bit_binary_stable_final.tar.gz
5.4_64bit_binary_stable_final.tar.gz
sersync
sersync
|
我这里将sersync放在了/usr/local/sersync/目录下
我这里修改了下confxml.xml文件
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
?>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
启动sersync
|
1
|
sersync2
|
|
1
|
xml
|
-n 启用线程数量
-d daemon方式启动
-o 指定配置文件
sersync整体同步一次
在sersync目录下运行./sersync2 -r
每当192.168.0.70 /opt/tongbu目录下上传文件会主动推送到192.168.0.31 /whsir目录下
如果推送失败则在15分钟后再次推送,我这里改的15分钟,如果连续两次失败,则不会在推送了,建议在192.168.0.31上做个rsync拉,确保文件一致