手机版
你好,游客 登录 注册
背景:
阅读新闻

Sersync使用指南

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

[日期:2012-02-06] 来源:Linux社区  作者:like7419 [字体: ]

XML配置说明
[root@localhost /data/test]#vi /home/like/software/GNU-Linux-x86/confxml.xml
sersync可选功能是通过xml配置文件来实现的,基本配置文件如下:
——————————————————————————————————————————————
01<?xml version="1.0" encoding="ISO-8859-1"?>
02<headversion="2.5">
03     <hosthostip="localhost"port="8008"></host>
04     <filterstart="false">
05         <excludeexpression="(.*)\.gz"></exclude>
06         <excludeexpression="^info/*"></exclude>
07     </filter>
08     <inotify>
09         <deletestart="true"/>
10         <createFolderstart="true"/>
           <createFilestart="true"/>
11     </inotify>
12     <debugstart="false"/>
13     <sersync>
14         <localpathwatch="/opt/tongbu1">
15             <remoteip="192.168.1.11"name="tongbu1"/>
16             <!--<remote ip="192.168.1.12" name="tongbu"/>-->
17             <!--<remote ip="192.168.1.13" name="tongbu"/>-->
18         </localpath>
19         <rsync>
20            <commonParams params="-artuz"/>
20             <authstart="false"users="root"passwordfile="/etc/rsync.pas"/>
21             <userDefinedPortstart="false"port="874"/><!-- port=874 -->
22             <timeoutstart="false"time="100"/><!-- timeout=100 -->
23             <sshstart="false"/>
24         </rsync>
25         <failLogpath="/tmp/rsync_fail_log.sh"timeToExecute="60"/><!--default every 60min execute once-->
26         <crontabstart="false"schedule="600"><!--600mins-->
27             <crontabfilterstart="false">
28                 <excludeexpression="*.gz"></exclude>
29                 <excludeexpression="info/*"></exclude>
30             </crontabfilter>
31         </crontab>
32         <pluginstart="false"name="command"/>
33     </sersync>
——————————————————————————————————————————————

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

filter文件过滤功能

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

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


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

XFS文件系统

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


文件监控与远程同步设置

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


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

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

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

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

linux
【内容导航】
第1页:sersync项目简介 第2页:sersync2 完全安装配置说明(一) 基本功能使用
第3页:sersync2 完全安装配置说明(二) 可选功能与xml高级配置 第4页:sersync2 完全安装配置说明(三) 插件基本配置和使用
第5页:sersync编译:sersync需要二次开发的用户请参考
相关资讯       Sersync 
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款