sersync的confxml.xml文件详解

<?xml version="1.0" encoding="ISO-8859-1"?>
<head version="2.5">
    <host hostip="localhost" port="8008"></host>    hostip与port是针对插件的保留字段,对于同步没有任何作用,保留默认即可。
    <debug start="false"/>			    开启debug模式,会在sersync正在运行的控制台,打印inotify事件与rsync同步命令。
    <fileSystem xfs="false"/>			    对于xfs文件系统的用户,需要将这个选项开启,才能是sersync正常工作。

 

<filter start="false">							
		<exclude expression="(.*)\.svn"></exclude>
		<exclude expression="(.*)\.gz"></exclude>
		<exclude expression="^info/*"></exclude>
		<exclude expression="^static/*"></exclude>
</filter>

对于sersync监控的文件,会默认过滤系统的临时文件(以"."开头,以"~"结尾),除了这些文件外,可以自定义其他需要过滤的文件。

<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监控参数,对于大多数应用,可以把createFile设置为false来提高性能,减少rsync通讯,因为拷贝文件到监控目录会产生create事件与close_write事件,所以如果关闭create事件,只监控文件拷贝时结束的事件close_write,同样可以实现文件完整同步。

注意:要将createFolder保持为true,如果将createFloder设置为false,则不会对产生的目录进行监控,该目录下的子文件与子目录也不会被监控,所以除非特殊需要,请开启。默认情况下对创建文件(目录)事件与删除文件(目录)事件都进行监控,如果项目中不需要删除远程目标服务器的文件(目录),则可以将delete参数设置为false,则不会删除事件监控。

<sersync>
		<localpath watch="/opt/tongbu">					/opt/tongbu目录为sersync主服务器本地待同步的目录,ip为从服务器的ip地址,name="tongbu1",tongbu1为rsync.conf中模块的名字。
			<remote ip="127.0.0.1" name="tongbu1"/>
			<!--<remote ip="192.168.8.39" name="tongbu"/>-->
			<!--<remote ip="192.168.8.40" name="tongbu"/>-->
		</localpath>
		
		<rsync>
			<commonParams params="-artuz"/>				rsync的同步参数
			<auth start="false" users="root" passwordfile="/etc/rsync.pas"/>      设置为true的时候,认证模式开启		
			<userDefinedPort start="false" port="874"/><!-- port=874 -->
			<timeout start="false" time="100"/><!-- timeout=100 -->
			<ssh start="false"/>						如果开启就是使用 rsync -e ssh的方式进行传输
		</rsync>
		
		<failLog path="/tmp/rsync_fail_log.sh" timeToExecute="60"/><!--default every 60mins execute once-->			失败日志脚本配置
		如果文件同步失败,会重新传送,再次失败就会写入rsync_fail_log.sh,然后每隔一段时间(timetoexecute进行设置)执行该脚本再次重新传送,然后清空该脚本。
		
		<crontab start="false" schedule="600"><!--600mins-->		每隔一段时间整体同步,,如果文件量比较大,crontab的时间间隔要设的大一些,否则可能增加通讯开销。如果开启了filter文件过滤功能,那么crontab整体同步也需要设置过滤,否则虽然实时同步的时候文件被过滤了,但crontab整体同步的时候,如果不单独设置crontabfilter,还会将需要过滤的文件同步到远程服务器,crontab的过滤正则与fileter过滤的不同。
			<crontabfilter start="false">							如果同时开启了filter与crontab,则要开启crontab的crontabfilter。
			<exclude expression="*.php"></exclude>
			<exclude expression="info/*"></exclude>
			</crontabfilter>
		</crontab>
		
		<plugin start="false" name="command"/>				设置为true,将文件同步到远程服务器后会条用name参数指定的插件。如果需要使用插件则需要在启动实例的时候加上-m参数
    </sersync>

  

<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>

当同步文件完成后,会调用command插件,如同步文件是test.php,则test.php文件再改动后,调用rsync同步到远程服务器后,调用comand插件,执行/bin/sh test.php suffix >/dev/null 2>&1
如果suffix设置了,则会放在inotify事件test.php之后,如果ignoError为true,则会添加>/dev/null 2>&1,当然还可以设置command的filter,当filter为true,include可以只对正则匹配到的文件调用command。

<plugin name="socket">	
		<localpath watch="/opt/tongbu">
			<deshost ip="192.168.138.20" port="8009"/>
		</localpath>
</plugin>
向指定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>

在同步的过程中将文件发送到目的服务器后刷新cdn接口。改模块是根据chainaCDN的协议,进行设计,当有文件产生的时候,就向cdn接口发送需要刷新的路径位置。
localpath是需要监控的目录,cdninfo标签制定了cdn接口的域名,端口号,以及用户名与密码。
sendurl标签是需要刷新的url的前缀。regexurl标签中的,regex属性为true时,使用match 属性的正则语句匹配inotify返回的路径信息,并将正则匹配到的部分作为url一部分。

举例:
如果产生文件事件为:/data0/htdocs/cms.xoyo.com/site/jx3.xoyo.com/image/a/123.txt
经过上面的match正则匹配后,最后刷新的路径是:http://pic.xoyo.com/cms/jx3/a/123.txt
如果regex属性为false,最后刷新的路径是:http://pic.xoyo.com/cms/jx3.xoyo.com/images/a/123.txt

</head>

  

 

转载于:https://www.cnblogs.com/bill2014/p/7417077.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值