[root@SERSYNC sersync]
1<?xml version=
"1.0"
encoding=
"ISO-8859-1"
?>
2<
head
version=
"2.5"
>
3 <host hostip=
"localhost"
port=
"8008"
><
/host
>
4 <debug start=
"false"
/>
5 <fileSystem xfs=
"false"
/>
对于sersync监控的文件,会默认过滤系统的临时文件(以“.”开头,以“~”结尾),除了这些文件外,在6-11行中,我们还可以自定义其它需要过滤的文件。
通过将 start 设置为
true
后可开启过滤功能,在exclude标签中可使用正则表达式。默认给出的两个例子分别是过滤以“.gz”结尾的文件与过滤监控目录下的info路径(监控路径
/info/
*),可以根据需求自己添加。但在开启的时候,自己一定要测试下,如果正则表达式出现错误,控制台会有相应提示。相比较使用 Rsync 的 exclude 功能,被过滤的路径,不会加入监控,大大减少 Rsync 同步的通讯量
6 <filter start=
"false"
>
7<exclude expression=
"(.*)\.svn"
><
/exclude
>
8<exclude expression=
"(.*)\.gz"
><
/exclude
>
9<exclude expression=
"^info/*"
><
/exclude
>
10<exclude expression=
"^static/*"
><
/exclude
>
11 <
/filter
>
第12-23行用来定义 inotify 监控参数,我们可以根据项目的特点来优化 Sersync。
对于大多数应用,可以尝试把 createFile(监控文件事件选项)设置为
false
来提高性能,进一步减少 Rsync通讯。因为拷贝文件到监控目录会产生 create 事件与 close_write 事件,所以如果关闭create 事件,只监控文件拷贝结束时的事件 close_write,同样可以实现文件完整同步。
注意:要使得 createFolder 保持为
true
,如果将createFolder设为
false
,则不会对产生的目录进行监控,该目录下的子文件与子目录也不会被监控,所以除非特殊需要,请开启。默认情况下对创建文件(目录)事件与删除文件(目录)事件都进行监控,如果项目中不需要删除远程目标服务器的文件(目录),则可以将 delete 参数设置为
false
,则不对删除事件进行监控。
12 <inotify>
13<delete start=
"true"
/>
14<createFolder start=
"true"
/>
15<createFile start=
"false"
/>
16<closeWrite start=
"true"
/>
17<moveFrom start=
"true"
/>
18<moveTo start=
"true"
/>
19<attrib start=
"false"
/>
20<modify start=
"false"
/>
21 <
/inotify
>
22
23 <sersync>
第24-28行用来定义所要同步和监控的目录文件。
/opt/tongbu
目录为sersync主服务器本地待同步的目录,ip=“192.168.8.39”为从服务器的ip地址,如果有多个服务器,依次列出来即可。name=“tongbu”,这里的tongbu为rsyncd.conf中的模块名字,即中括号中的名称。
24<localpath
watch
=
"/opt/tongbu"
>
25 <remote ip=
"127.0.0.1"
name=
"tongbu1"
/>
26 <!--<remote ip=
"192.168.8.39"
name=
"tongbu"
/>-->
27 <!--<remote ip=
"192.168.8.40"
name=
"tongbu"
/>-->
28<
/localpath
>
第29-35行用来定义
rsync
的命令参数
在 commonParams 项,我们可以自定义
rsync
的同步参数,默认是-artuz,auth start=“
false
”设置为
true
的时候,使用
rsync
的认证模式传送,需要配置user与passwordfile(-password-
file
=
/etc/rsync
.pas)来使用。userDefinedPort 当远程同步目标服务器的
rsync
端口不是默认端口的时候使用(-port=874)。timeout设置
rsync
的timeout事件(-timeout=100)。<
ssh
start=”
false
”/>如果开启表示
ssh
使用
rsync
-e
ssh
的方式进行传输。
29<
rsync
>
30 <commonParams params=
"-artuz"
/>
31 <auth start=
"false"
users
=
"root"
passwordfile=
"/etc/rsync.pas"
/>
32 <userDefinedPort start=
"false"
port=
"874"
/><!-- port=874 -->
33 <timeout start=
"false"
time
=
"100"
/><!-- timeout=100 -->
34 <
ssh
start=
"false"
/>
35<
/rsync
>
第36行用来定义失败日志脚本配置
如果文件同步传输失败,会重新传送,再次失败就会写入 rsync_fail_log.sh,然后每隔一段时间(timeToExecute进行设置)执行该脚本再次重新传送,然后清空该脚本。可以通过path来设置日志路径
36<failLog path=
"/tmp/rsync_fail_log.sh"
timeToExecute=
"60"
/><!--default every 60mins execute once-->
第37-42行用来定义Crontab定期整体同步功能
Crontab可以对监控路径与远程目标主机每隔一段时间进行一次整体同步,可能由于一些原因两次失败重传都失败了,这个时候如果开启了
crontab
功能,还可以进行一次保证各个服务器文件一致,如果文件量比较大,
crontab
的时间间隔要设的大一些,否则可能增加通讯开销,schedule这个参数是设置
crontab
的时间间隔,默认是600分钟。
如果开启了 filter 文件过滤功能,那么
crontab
整体同步也需要设置过滤,否则虽然实时同步的时候文件被过滤了,但
crontab
整体同步的时候,如果不单独设置crontabfilter,还会将需过滤的文件同步到远程从服务器,
crontab
的过滤正则与filter过滤的不同,也给出了两个实例分别对应与过滤文件与目录,总之如果同时开启了filter与
crontab
,则要开启
crontab
的crontabfilter,并按示例设置使其与filter的过滤一一对应。
37<
crontab
start=
"false"
schedule=
"600"
><!--600mins-->
38 <crontabfilter start=
"false"
>
39<exclude expression=
"*.php"
><
/exclude
>
40<exclude expression=
"info/*"
><
/exclude
>
41 <
/crontabfilter
>
42<
/crontab
>
43<plugin start=
"false"
name=
"command"
/>
44 <
/sersync
>
45
从46行到行尾,都是插件的相关信息。当plugin标签设置为
true
时候,在同步文件或路径到远程服务器之后,会调用插件。通过name参数指定需要执行的插件。目前支持的有
command
、refreshCDN、socket、http四种插件。其中,http插件目前由于兼容性原因已经去除,以后会重新加入。
46 <plugin name=
"command"
>
47<param prefix=
"/bin/sh"
suffix=
""
ignoreError=
"true"
/><!--prefix
/opt/tongbu/mmm
.sh suffix-->
48<filter start=
"false"
>
49 <include expression=
"(.*)\.php"
/>
50 <include expression=
"(.*)\.sh"
/>
51<
/filter
>
52 <
/plugin
>
53
第54-58行为插件socket的相关配置
socket插件,开启该模块,则向指定ip与端口发送inotify所产生的文件路径信息
54 <plugin name=
"socket"
>
55<localpath
watch
=
"/opt/tongbu"
>
56 <deshost ip=
"192.168.138.20"
port=
"8009"
/>
57<
/localpath
>
58 <
/plugin
>
第59-65行为插件refreshCDN的相关配置
refreshCDN 用来在同步过程中将文件发送到目地服务器后,刷新cdn接口。如果不想使用,则将start属性设为
false
即可。该模块根据chinaCDN的协议,进行设计,当有文件产生的时候,就向cdn解耦发送需要刷新的路径为止。其中localpath
watch
=“
/data0/htdocs/cms
.xoyo.com
/site/
”是需要监控的目录。cdinfo标签指定了cdn接口的域名,端口号,以及用户名与密码。sendurl 标签是需要刷新的url的前缀。regexurl 标签中,regex属性为
true
时候,使用match属性的正则语句匹配inotify返回的路径信息,并将正则匹配到的部分作为url一部分
下面配置文件自带的意思为,如果产生文件事件为:
/data0/htdoc/cms
.xoyo.com
/site/jx3
.xoyo.com
/image/a/123
.txt
经过上面的match正则匹配后,最后刷新的路径是:http:
//pic
.xoyo.com
/cms/a/123
.txt
如果regex属性为
false
,最后刷新的路径就是:http:
//pic
.xoyo.com
/cms/jx3
.xoyo.com
/images/a/123
.txt
59 <plugin name=
"refreshCDN"
>
60<localpath
watch
=
"/data0/htdocs/cms.xoyo.com/site/"
>
61 <cdninfo domainname=
"ccms.chinacache.com"
port=
"80"
username=
"xxxx"
passwd
=
"xxxx"
/>
62 <sendurl base=
"http://pic.xoyo.com/cms"
/>
63 <regexurl regex=
"false"
match=
"cms.xoyo.com/site([/a-zA-Z0-9]*).xoyo.com/images"
/>
64<
/localpath
>
65 <
/plugin
>
66<
/head
>