sersync2 完全安装配置说明 ----可选功能与xml高级配置

来源:互联网 发布:郑州经传软件招聘 编辑:程序博客网 时间:2024/05/21 08:41

XML配置说明


sersync可选功能是通过xml配置文件来实现的,基本配置文件如下:
——————————————————————————————————————————————
01 <?xml version="1.0" encoding="ISO-8859-1"?>
02 <head version="2.5">
03     <host hostip="localhost"port="8008"></host>
04     <filter start="false">
05         <exclude expression="(.*)\.gz"></exclude>
06         <exclude expression="^info/*"></exclude>
07     </filter>
08     <inotify>
09         <delete start="true"/>
10         <createFolder start="true"/>
           <createFile start="true"/>
11     </inotify>
12     <debug start="false"/>
13     <sersync>
14         <localpath watch="/opt/tongbu">
15             <remote ip="192.168.0.104" name="tongbu1"/>
16             <!--<remote ip="192.168.8.39" name="tongbu"/>-->
17             <!--<remote ip="192.168.8.40" name="tongbu"/>-->
18         </localpath>
19         <rsync>
20            <commonParams params="-artuz"/>
20             <auth start="false" users="root" passwordfile="/etc/rsync.pas"/>
21             <userDefinedPort start="false" port="874"/><!-- port=874 -->
22             <timeout start="false"time="100"/><!-- timeout=100 -->
23             <ssh start="false"/>
24         </rsync>
25         <failLog path="/tmp/rsync_fail_log.sh" timeToExecute="60"/><!--default every 60min execute once-->
26         <crontab start="false"schedule="600"><!--600mins-->
27             <crontabfilter start="false">
28                 <exclude expression="*.gz"></exclude>
29                 <exclude expression="info/*"></exclude>
30             </crontabfilter>
31         </crontab>
32         <plugin start="false"name="command"/>
33     </sersync>
——————————————————————————————————————————————

下面做逐行的进行解释说明:
03     <host hostip="localhost"port="8008"></host>
hostip与port是针对插件的保留字段,对于同步功能没有任何作用,保留默认即可。

filter文件过滤功能

对于sersync监控的文件,会默认过滤系统的临时文件(以“.”开头,以“~”结尾),除了这些文件外,可以自定义其他需要过滤的文件。
04     <filter start="true">
05         <exclude expression="(.*)\.gz"></exclude>
06         <exclude expression="^info/*"></exclude>
07     </filter>
start设置为 true,在exclude标签中,填写正则表达式,默认给出两个例子分别是过滤以".gz"结尾的文件与过滤监控目录下的info路径(监控路径/info/*),可以根据需要添加,但开启的时候,自己测试一下,正则表达式如果出现错误,控制台会有提示。相比较使用rsync 的exclude功能,被过滤的路径,不会加入监控,大大减少rsync的通讯量。

inotify监控参数设定
(优化)
对于inotify监控参数可以进行设置,根据您项目的特点优化srsync。
08     <inotify>
09         <delete start="true"/>
10         <createFolder start="true"/>
11         <createFile start="true"/>
12     </inotify>
对于大多数应用,可以尝试把createFile(监控文件事件选项)设置为false来提高性能,减少 rsync通讯。因为拷贝文件到监控目录会产生create事件与close_write事件,所以如果关闭create事件,只监控文件拷贝结束时的事 件close_write,同样可以实现文件完整同步。
注意:强将createFolder保持为true,如果将createFolder设为false,则不会对产生的目录进行监控,该目录下的子文件与子目录也不会被监控。所以除非特殊需要,请开启。
默认情况下对创建文件(目录)事件与删除文件(目录)事件都进行监控,如果项目中不需要删除远程目标服务器的文件(目录),则可以将delete 参数设置为false,则不对删除事件进行监控。





Debug开启
12     <debug start="false"/>
设置为true,开启debug模式,会在sersync正在运行的控制台,打印inotify事件与rsync同步命令。

XFS文件系统

<fileSystem xfs="false"/>
对于xfs文件系统的用户,需要将这个选项开启,才能使sersync正常工作


文件监控与远程同步设置

3     <sersync>
14         <localpath watch="/opt/tongbu">
15             <remote ip="192.168.0.104"name="tongbu1"/>
16             <!--<remote ip="192.168.8.39" name="tongbu"/>-->
17             <!--<remote ip="192.168.8.40" name="tongbu"/>-->
18         </localpath>
详见
sersync2 完全安装配置说明(一) ----基本功能使用

Rsync参数配置
19         <rsync>
20            <commonParams params="-artuz"/>
20             <auth start="false" users="root" passwordfile="/etc/rsync.pas"/>
21             <userDefinedPort start="false" port="874"/><!-- port=874 -->
22             <timeout start="false"time="100"/><!-- timeout=100 -->
23             <ssh start="false"/>
24         </rsync>
commonParams可以用户自定义rsync参数,默认是-artuz
auth start="false" 设置为true的时候,使用rsync的认证模式传送,需要配置user与passwrodfile(--password-file=/etc/rsync.pas),来使用。userDefinedPort 当远程同步目标服务器的rsync端口不是默认端口的时候使用(--port=874)。timeout设置rsync的timeout时间(--timeout=100)。ssh使用rsync -e ssh的方式进行传输。

失败日志脚步配置
25         <failLog path="/tmp/rsync_fail_log.sh"timeToExecute="60"/><!--default every 60min
对于失败的传输,会进行重新传送,再次失败就会写入rsync_fail_log,然后每隔一段时间(timeToExecute进行设置)执行该脚本再次重新传送,然后清空该脚本。可以通过path来设置日志路径。

Crontab定期整体同步功能
26         <crontab start="false"schedule="600"><!--600mins-->
27             <crontabfilter start="false">
28                 <exclude expression="*.gz"></exclude>
29                 <exclude expression="info/*"></exclude>
30             </crontabfilter>
31         </crontab>
crontab可以对监控路径与远程目标主机每隔一段时间进行一次整体同步,可能由于一些原因两次失败重传都失败了,这个时候如果开启了crontab功能,还可以进一步保证各个服务器文件一致,如果文件量比较大,crontab的时间间隔要设的大一些,否则可能增加通讯开销。schedule这个参数是设置crontab的时间间隔,默认是600分钟
如果开启了filter文件过滤功能,那么crontab整体同步也需要设置过滤,否则虽然实时同步的时候文件被过滤了,但crontab整体同步的时候如果不单独设置crontabfilter,还会将需过滤的文件同步到远程,crontab的过滤正则与filter过滤的不同,也给出了两个实例分别对应与过滤文件与目录。总之如果同时开启了filter与crontab,则要开启crontab的crontabfilter,并按示例设置使其与filter的过滤一一对应。

插件设置
32         <plugin start="false"name="command"/>
当设置为true的时候,将文件同步到远程服务器后会调用name参数指定的插件。详见请看
插件设置。


原创粉丝点击