|
<?xml version="1.0" encoding="ISO-8859-1"?>
<head version="2.5">
<host hostip="localhost" port="8008"></host>
<!--hostip与port是针对插件的保留字段,对于同步功能没有任何作用,保留默认即可。-->
<debug start="false"/>
<!--该行为Debug开启开关。true为开启debug模式,会在sersync正在运行的控制台,打印 inotify 事件与 rsync 同步命令,生产环境一般不开启.-->
<fileSystem xfs="false"/>
<!--对于XFS文件系统的用户,需要将这个选项开启,才能使sersync正常工作
对于sersync监控的文件,会默认过滤系统的临时文件(以"."开头,以"~"结尾),除了这些文件外,
在15-20行中,我们还可以自定义其它需要过滤的文件。
通过将 start 设置为 true 后可开启过滤功能,在exclude标签中可使用正则表达式。
默认给出的两个例子分别是过滤以".gz"结尾的文件与过滤监控目录下的info路径(监控路径/info/*),可以根据需求自己添加。
但在开启的时候,自己一定要测试下,如果正则表达式出现错误,控制台会有相应提示。
相比较使用 Rsync 的 exclude 功能,被过滤的路径,不会加入监控,大大减少 Rsync 同步的通讯量-->
<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="false"/>
<modify start="false"/>
</inotify>
<!--用来定义 inotify 监控参数,我们可以根据项目的特点来优化 Sersync。
对于大多数应用,可以尝试把 createFile(监控文件事件选项)设置为false来提高性能,进一步减少 Rsync通讯。因为拷贝文件到监控目录会产生 create 事件与 close_write 事件,所以如果关闭create 事件,只监控文件拷贝结束时的事件 close_write,同样可以实现文件完整同步。
注意:要使得 createFolder 保持为true,如果将createFolder设为false,则不会对产生的目录进行监控,该目录下的子文件与子目录也不会被监控,所以除非特殊需要,请开启。默认情况下对创建文件(目录)事件与删除文件(目录)事件都进行监控,如果项目中不需要删除远程目标服务器的文件(目录),则可以将 delete 参数设置为 false,则不对删除事件进行监控。-->
<sersync>
<localpath watch="/home/wwwroot/www.dwhd.org">
<remote ip="172.16.6.101" name="home_wwwroot_www_dwhd_org"/>
<!--<remote ip="192.168.8.39" name="tongbu"/>-->
<!--<remote ip="192.168.8.40" name="tongbu"/>-->
</localpath>
<!--/home/wwwroot/www.dwhd.org目录为sersync主服务器本地待同步的目录,ip="172.16.6.100"为从服务器的ip地址,如果有多个服务器,依次列出来即可。name="home_wwwroot_www_dwhd_org",这里的home_wwwroot_www_dwhd_org为rsyncd.conf中的模块名字,即中括号中的名称。-->
<rsync>
<commonParams params="-artuz"/>
<auth start="true" users="lookback" passwordfile="/etc/passwd.txt"/>
<userDefinedPort start="false" port="874"/><!-- port=874 -->
<timeout start="false" time="100"/><!-- timeout=100 -->
<ssh start="false"/>
</rsync>
<!--在 commonParams 项,我们可以自定义rsync的同步参数,默认是-artuz,auth start="false"设置为true的时候,使用rsync的认证模式传送,需要配置user与passwordfile(-password-file=/etc/passwd.txt)来使用。userDefinedPort 当远程同步目标服务器的rsync端口不是默认端口的时候使用(-port=874)。timeout设置rsync的timeout事件(-timeout=100)。<ssh start="false"/>如果开启表示ssh使用rsync -e ssh的方式进行传输。-->
<failLog path="/tmp/rsync_fail_log.sh" timeToExecute="5"/><!--default every 60mins execute once-->
<!--用来定义失败日志脚本配置,如果文件同步传输失败,会重新传送,再次失败就会写入 rsync_fail_log.sh,然后每隔一段时间(timeToExecute进行设置)执行该脚本再次重新传送,然后清空该脚本。可以通过path来设置日志路径-->
<crontab start="true" schedule="600"><!--600mins-->
<crontabfilter start="false">
<exclude expression="*.php"></exclude>
<exclude expression="info/*"></exclude>
</crontabfilter>
</crontab>
<!--用来定义Crontab定期整体同步功能,Crontab可以对监控路径与远程目标主机每隔一段时间进行一次整体同步,可能由于一些原因两次失败重传都失败了,这个时候如果开启了 crontab 功能,还可以进行一次保证各个服务器文件一致,如果文件量比较大,crontab的时间间隔要设的大一些,否则可能增加通讯开销,schedule这个参数是设置crontab的时间间隔,默认是600分钟。
如果开启了 filter 文件过滤功能,那么crontab整体同步也需要设置过滤,否则虽然实时同步的时候文件被过滤了,但 crontab 整体同步的时候,如果不单独设置crontabfilter,还会将需过滤的文件同步到远程从服务器,crontab的过滤正则与filter过滤的不同,也给出了两个实例分别对应与过滤文件与目录,总之如果同时开启了filter与crontab,则要开启crontab的crontabfilter,并按示例设置使其与filter的过滤一一对应。-->
<plugin start="false" name="command"/>
</sersync>
<!--此处到行尾,都是插件的相关信息。当plugin标签设置为true时候,在同步文件或路径到远程服务器之后,会调用插件。通过name参数指定需要执行的插件。目前支持的有command、refreshCDN、socket、http四种插件。其中,http插件目前由于兼容性原因已经去除,以后会重新加入。-->
<plugin name="command">
<param prefix="/bin/sh" suffix="" ignoreError="true"/> <!--prefix /opt/tongbu/mmm.sh suffix-->
<filter start="false">
<include expression="(.*)\.php"/>
<include expression="(.*)\.sh"/>
</filter>
</plugin>
<plugin name="socket">
<localpath watch="/opt/tongbu">
<deshost ip="192.168.138.20" port="8009"/>
</localpath>
</plugin>
<!--socket插件,开启该模块,则向指定ip与端口发送inotify所产生的文件路径信息-->
<plugin name="refreshCDN">
<localpath watch="/data0/htdocs/cms.xoyo.com/site/">
<cdninfo domainname="ccms.chinacache.com" port="80" username="xxxx" passwd="xxxx"/>
<sendurl base="http://pic.xoyo.com/cms"/>
<regexurl regex="false" match="cms.xoyo.com/site([/a-zA-Z0-9]*).xoyo.com/images"/>
</localpath>
</plugin>
<!--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-->
</head>
|