zoukankan      html  css  js  c++  java
  • 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>
    

      

  • 相关阅读:
    post请求返回404
    启动网关服务报错 Unable to find GatewayFilterFactory with name RequestRateLimiter
    数据库远程连接linux报错2003 can't connect to MySQL server on ip (0) 防火墙没有开放端口3306
    idea下maven项目打包部署到tomcat服务器
    修改Idea背景色
    20种源代码测试工具
    作为一名测试工程师,需要具备哪些能力
    Android自动化测试工具——monkey简介及入门
    appium关于定位元素
    appium testcase2
  • 原文地址:https://www.cnblogs.com/bill2014/p/7417077.html
Copyright © 2011-2022 走看看