<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0">
<channel>
<title><![CDATA[沧海一粟]]></title> 
<link>http://www.dzhope.com/index.php</link> 
<description><![CDATA[Web系统架构与服务器运维,php开发]]></description> 
<language>zh-cn</language> 
<copyright><![CDATA[沧海一粟]]></copyright>
<item>
<link>http://www.dzhope.com/post//</link>
<title><![CDATA[sersync2 实时同步]]></title> 
<author>jed &lt;jed521@163.com&gt;</author>
<category><![CDATA[服务器技术]]></category>
<pubDate>Sun, 22 Dec 2013 09:07:30 +0000</pubDate> 
<guid>http://www.dzhope.com/post//</guid> 
<description>
<![CDATA[ 
	自动同步文件或者是目录<br/><br/>实现的方式：<br/><br/>在同步服务器上开启sersync，将监控路径中的文件同步到目标服务器，因此需要在同步服务器配置sersync，在同步目标服务器配置rsync<br/><br/>实验机器的地址分配：<br/><br/>Rsync 服务器：&nbsp;&nbsp; 192.168.1.112<br/><br/>Sersync2 服务器：192.168.1.110<br/><br/>系统环境<br/><div class="code"><br/>&#91;root@liyao home&#93;# uname -a<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Linux liyao 2.6.18-194.el5 #1 SMP Fri Apr 2 14:58:35 EDT 2010 i686 i686 i386 GNU/Linux<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &#91;root@liyao home&#93;#<br/></div><br/>一、&nbsp;&nbsp;&nbsp;&nbsp; rsync 服务器的配置<br/><br/>1.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 先查看下是否安装了 rsync 软件包<br/><div class="code"><br/>&#91;root@liyao ~&#93;# rpm -qa &#124; grep rsync<br/><br/>rsync-2.6.8-3.1<br/><br/>&#91;root@liyao ~&#93;#<br/></div><br/>2.&nbsp;&nbsp;&nbsp;&nbsp; 如果系统默认安装了 rsync 软件包，我们可以使用 yum 命令将其卸载<br/><div class="code"><br/>&#91;root@liyao ~&#93;# yum remove -y rsync<br/><br/>Loaded plugins: fastestmirror<br/><br/>Setting up Remove Process<br/><br/>Resolving Dependencies<br/><br/>--&gt; Running transaction check<br/><br/>---&gt; Package rsync.i386 0:2.6.8-3.1 set to be erased<br/><br/>--&gt; Finished Dependency Resolution<br/><br/> <br/><br/>Dependencies Resolved<br/><br/> <br/><br/>================================================================================<br/><br/> Package&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Arch&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Version&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Repository&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Size<br/><br/>================================================================================<br/><br/>Removing:<br/><br/> rsync&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; i386&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 2.6.8-3.1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; installed&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 392 k<br/><br/> <br/><br/>Transaction Summary<br/><br/>================================================================================<br/><br/>Remove&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;1 Package(s)<br/><br/>Reinstall&nbsp;&nbsp;&nbsp;&nbsp; 0 Package(s)<br/><br/>Downgrade&nbsp;&nbsp;&nbsp;&nbsp; 0 Package(s)<br/><br/> <br/><br/>Downloading Packages:<br/><br/>Running rpm_check_debug<br/><br/>Running Transaction Test<br/><br/>Finished Transaction Test<br/><br/>Transaction Test Succeeded<br/><br/>Running Transaction<br/><br/>&nbsp;&nbsp;Erasing&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;: rsync&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;1/1<br/><br/> <br/><br/>Removed:<br/><br/>&nbsp;&nbsp;rsync.i386 0:2.6.8-3.1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br/><br/> <br/><br/>Complete!<br/><br/>&#91;root@liyao ~&#93;#<br/></div><br/>3.&nbsp;&nbsp;&nbsp;&nbsp; 下载 rsync 3.0 的源码包<br/><div class="code"><br/><br/>&#91;root@liyao~&#93;#wget-chttp://rsync.samba.org/ftp/rsync/rsync-3.0.8.tar.gz<br/><br/>--2011-08-20 08:05:05--&nbsp;&nbsp;http://rsync.samba.org/ftp/rsync/rsync-3.0.8.tar.gz<br/><br/>Resolving rsync.samba.org... 216.83.154.106, 2001:470:1f05:1a07::1<br/><br/>Connecting to rsync.samba.org&#124;216.83.154.106&#124;:80... connected.<br/><br/>HTTP request sent, awaiting response... 200 OK<br/><br/>Length: 790722 (772K) &#91;application/x-gzip&#93;<br/><br/>Saving to: `rsync-3.0.8.tar.gz&#039;<br/><br/> <br/><br/>100%&#91;======================================&gt;&#93; 790,722&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;153K/s&nbsp;&nbsp; in 5.7s&nbsp;&nbsp; <br/><br/> <br/><br/>2011-08-20 08:05:11 (135 KB/s) - `rsync-3.0.8.tar.gz&#039; saved &#91;790722/790722&#93;<br/></div><br/><br/>4.&nbsp;&nbsp;&nbsp;&nbsp; 将该软件包解压缩，并且进行编译安装<br/><div class="code"><br/>&#91;root@liyao ~&#93;# tar zxf rsync-3.0.8.tar.gz<br/><br/>&#91;root@liyao ~&#93;# cd rsync-3.0.8<br/><br/>&#91;root@liyao rsync-3.0.8&#93;# ./configure --prefix=/usr/ &amp;&amp; make &amp;&amp; make install<br/></div><br/>5.&nbsp;&nbsp;&nbsp;&nbsp; 建立 rsync 服务器的配置文件<br/><div class="code"><br/>uid = nobody<br/><br/>gid = nobody<br/><br/>use chroot = no<br/><br/>strict modes = yes<br/><br/>max connections = 200<br/><br/>pid file = /var/run/rsyncd.pid<br/><br/>lock file = /var/run/rsync.lock<br/><br/>log file = /var/log/rsyncd.log <br/><br/>&#91;test&#93;<br/><br/>path = /home/<br/><br/>comment = test<br/><br/>read only = no<br/><br/>write only = no<br/><br/>ignore errors = yes<br/><br/>list = yes<br/><br/>uid = root<br/><br/>gid = root<br/></div><br/>6.&nbsp;&nbsp;&nbsp;&nbsp; 启动 rsync 的服务<br/>[/code]<br/>&nbsp;&nbsp;[root@liyao ~]# rsync --daemon<br/><br/>[root@liyao ~]# netstat -npl &#124; grep 873<br/><br/>tcp&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;0&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;0 0.0.0.0:873&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 0.0.0.0:*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; LISTEN&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;7731/rsync&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br/><br/>tcp&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;0&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;0 :::873&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:::*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;LISTEN&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;7731/rsync <br/>[/code]<br/> <br/><br/>二、&nbsp;&nbsp;&nbsp;&nbsp; 配置Sersync2 服务器<br/><br/>二进制直接可运行<br/><div class="code"><br/>wget http://sersync.googlecode.com/files/sersync2.5_64bit_binary_stable_final.tar.gz<br/><br/>http://sersync.googlecode.com/files/sersync2.5_32bit_binary_stable_final.tar.gz<br/></div><br/>1、将该软件包下载下来之后解压缩，并进行安装<br/><div class="code"><br/>&#91;root@liyao ~&#93;# tar zxf sersync2.5_32bit_binary_stable_final.tar.gz<br/><br/>&#91;root@liyao ~&#93;# ls<br/><br/>anaconda-ks.cfg&nbsp;&nbsp;install.log.syslog<br/><br/>GNU-Linux-x86&nbsp;&nbsp;&nbsp;&nbsp;sersync2.5_32bit_binary_stable_final.tar.gz<br/><br/>install.log<br/><br/>&#91;root@liyao ~&#93;# cd GNU-Linux-x86/<br/><br/>&#91;root@liyao GNU-Linux-x86&#93;# ls<br/><br/>confxml.xml&nbsp;&nbsp;sersync2<br/><br/>&#91;root@liyao GNU-Linux-x86&#93;# mkdir /etc/sersync2<br/><br/>&#91;root@liyao GNU-Linux-x86&#93;# cp confxml.xml /etc/sersync2/<br/><br/>&#91;root@liyao GNU-Linux-x86&#93;# cp sersync2 /usr/bin/<br/></div><br/># 安装该软件只要把软件中的文件拷贝到相应的目录即可<br/><br/>2. 修改 Sersync2 的配置文件<br/><div class="code"><br/>&#91;root@liyao ~&#93;# cat /etc/sersync2/confxml.xml<br/><br/>&lt;?xml version=&quot;1.0&quot; encoding=&quot;ISO-8859-1&quot;?&gt;<br/><br/>&lt;head version=&quot;2.5&quot;&gt;<br/><br/>&nbsp;&nbsp;&nbsp;&nbsp;&lt;host hostip=&quot;localhost&quot; port=&quot;8008&quot;&gt;&lt;/host&gt;<br/><br/>&nbsp;&nbsp;&nbsp;&nbsp;&lt;debug start=&quot;false&quot;/&gt;<br/><br/>&nbsp;&nbsp;&nbsp;&nbsp;&lt;fileSystem xfs=&quot;false&quot;/&gt;<br/><br/>&nbsp;&nbsp;&nbsp;&nbsp;&lt;filter start=&quot;false&quot;&gt;<br/><br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;exclude expression=&quot;(.*)&#92;.svn&quot;&gt;&lt;/exclude&gt;<br/><br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;exclude expression=&quot;(.*)&#92;.gz&quot;&gt;&lt;/exclude&gt;<br/><br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;exclude expression=&quot;^info/*&quot;&gt;&lt;/exclude&gt;<br/><br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;exclude expression=&quot;^static/*&quot;&gt;&lt;/exclude&gt;<br/><br/>&nbsp;&nbsp;&nbsp;&nbsp;&lt;/filter&gt;<br/><br/>&nbsp;&nbsp;&nbsp;&nbsp;&lt;inotify&gt;<br/><br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;delete start=&quot;true&quot;/&gt;<br/><br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;createFolder start=&quot;true&quot;/&gt;<br/><br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;createFile start=&quot;false&quot;/&gt;<br/><br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;closeWrite start=&quot;true&quot;/&gt;<br/><br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;moveFrom start=&quot;true&quot;/&gt;<br/><br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;moveTo start=&quot;true&quot;/&gt;<br/><br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;attrib start=&quot;false&quot;/&gt;<br/><br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;modify start=&quot;false&quot;/&gt;<br/><br/>&nbsp;&nbsp;&nbsp;&nbsp;&lt;/inotify&gt;<br/><br/> <br/><br/>&nbsp;&nbsp;&nbsp;&nbsp;&lt;sersync&gt;<br/><br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;localpath watch=&quot;/home&quot;&gt;<br/><br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;remote ip=&quot;192.168.1.112&quot; name=&quot;test&quot;/&gt;<br/><br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;# 指定 rsyncd 服务器的地址和备份的模块名称<br/><br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;!--&lt;remote ip=&quot;192.168.8.39&quot; name=&quot;tongbu&quot;/&gt;--&gt;<br/><br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;!--&lt;remote ip=&quot;192.168.8.40&quot; name=&quot;tongbu&quot;/&gt;--&gt;<br/><br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;/localpath&gt;<br/><br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;rsync&gt;<br/><br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;commonParams params=&quot;-artuz&quot;/&gt;<br/><br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;auth start=&quot;false&quot; users=&quot;root&quot; passwordfile=&quot;/etc/rsync.pas&quot;/&gt;<br/><br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;userDefinedPort start=&quot;false&quot; port=&quot;874&quot;/&gt;&lt;!-- port=874 --&gt;<br/><br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;timeout start=&quot;false&quot; time=&quot;100&quot;/&gt;&lt;!-- timeout=100 --&gt;<br/><br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;ssh start=&quot;false&quot;/&gt;<br/><br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;/rsync&gt;<br/><br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;failLog path=&quot;/var/log/rsync_fail.log&quot; timeToExecute=&quot;60&quot;/&gt;&lt;!--default every 60mins execute once--&gt;<br/><br/># 指定日志存放的路径<br/><br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;crontab start=&quot;false&quot; schedule=&quot;600&quot;&gt;&lt;!--600mins--&gt;<br/><br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;crontabfilter start=&quot;false&quot;&gt;<br/><br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;exclude expression=&quot;*.php&quot;&gt;&lt;/exclude&gt;<br/><br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;exclude expression=&quot;info/*&quot;&gt;&lt;/exclude&gt;<br/><br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;/crontabfilter&gt;<br/><br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;/crontab&gt;<br/><br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;plugin start=&quot;false&quot; name=&quot;command&quot;/&gt;<br/><br/>&nbsp;&nbsp;&nbsp;&nbsp;&lt;/sersync&gt;<br/><br/> <br/><br/>&nbsp;&nbsp;&nbsp;&nbsp;&lt;plugin name=&quot;command&quot;&gt;<br/><br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;param prefix=&quot;/bin/sh&quot; suffix=&quot;&quot; ignoreError=&quot;true&quot;/&gt;&nbsp;&nbsp;&lt;!--prefix /opt/tongbu/mmm.sh suffix--&gt;<br/><br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;filter start=&quot;false&quot;&gt;<br/><br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;include expression=&quot;(.*)&#92;.php&quot;/&gt;<br/><br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;include expression=&quot;(.*)&#92;.sh&quot;/&gt;<br/><br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;/filter&gt;<br/><br/>&nbsp;&nbsp;&nbsp;&nbsp;&lt;/plugin&gt;<br/><br/> <br/><br/>&nbsp;&nbsp;&nbsp;&nbsp;&lt;plugin name=&quot;socket&quot;&gt;<br/><br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;localpath watch=&quot;/opt/tongbu&quot;&gt;<br/><br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;deshost ip=&quot;192.168.138.20&quot; port=&quot;8009&quot;/&gt;<br/><br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;/localpath&gt;<br/><br/>&nbsp;&nbsp;&nbsp;&nbsp;&lt;/plugin&gt;<br/><br/>&nbsp;&nbsp;&nbsp;&nbsp;&lt;plugin name=&quot;refreshCDN&quot;&gt;<br/><br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;localpath watch=&quot;/data0/htdocs/cms.xoyo.com/site/&quot;&gt;<br/><br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;cdninfo domainname=&quot;ccms.chinacache.com&quot; port=&quot;80&quot; username=&quot;xxxx&quot; passwd=&quot;xxxx&quot;/&gt;<br/><br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;sendurl base=&quot;http://pic.xoyo.com/cms&quot;/&gt;<br/><br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;regexurl regex=&quot;false&quot; match=&quot;cms.xoyo.com/site(&#91;/a-zA-Z0-9&#93;*).xoyo.com/images&quot;/&gt;<br/><br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;/localpath&gt;<br/><br/>&nbsp;&nbsp;&nbsp;&nbsp;&lt;/plugin&gt;<br/><br/>&lt;/head&gt;<br/><br/>&#91;root@liyao ~&#93;#<br/></div><br/><br/>3. 我们来运行如下的备份命令<br/><br/>在运行备份命令之前我们先看下 /home 这个目录下面有文件或者是目录<br/><div class="code"><br/>&#91;root@liyao home&#93;# ls -l<br/><br/>total 4<br/><br/>drwxr-xr-x 2 root root 4096 Aug 20 08:51 liyao<br/><br/>&#91;root@liyao home&#93;#<br/><br/>&#91;root@liyao ~&#93;# sersync2 -r -d -o /etc/sersync2/confxml.xml<br/><br/>set the system param<br/><br/>execute：echo 50000000 &gt; /proc/sys/fs/inotify/max_user_watches<br/><br/>execute：echo 327679 &gt; /proc/sys/fs/inotify/max_queued_events<br/><br/>parse the command param<br/><br/>option: -r&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;rsync all the local files to the remote servers before the sersync work<br/><br/>option: -d&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;run as a daemon<br/><br/>option: -o&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;config xml name：&nbsp;&nbsp;/etc/sersync2/confxml.xml<br/><br/>daemon thread num: 10<br/><br/>parse xml config file<br/><br/>host ip : localhost&nbsp;&nbsp;&nbsp;&nbsp; host port: 8008<br/><br/>daemon start，sersync run behind the console<br/><br/>config xml parse success<br/><br/>please set /etc/rsyncd.conf max connections=0 Manually<br/><br/>sersync working thread 12&nbsp;&nbsp;= 1(primary thread) + 1(fail retry thread) + 10(daemon sub threads)<br/><br/>Max threads numbers is: 22 = 12(Thread pool nums) + 10(Sub threads)<br/><br/>please according your cpu ，use -n param to adjust the cpu rate<br/><br/>------------------------------------------<br/><br/>rsync the directory recursivly to the remote servers once<br/><br/>working please wait...<br/><br/>execute command: cd /home &amp;&amp; rsync -artuz -R --delete ./ 192.168.1.112::test &gt;/dev/null 2&gt;&amp;1<br/><br/>run the sersync:<br/><br/>watch path is: /home<br/></div><br/>4. 我们到 rsyncd 服务器（1.112）的 /home 目录下看看是否有我在 1.110 /home/liyao 这个目录<br/><div class="code"><br/>&#91;root@liyao home&#93;# ls<br/><br/>liyao<br/><br/>&#91;root@liyao home&#93;#<br/><br/> </div><br/><br/>那我们在从 1.110 的 /home 目录下创建 abc 目录，不用执行任何命令他会自动同步到 1.112 上<br/><div class="code"><br/>&#91;root@liyao home&#93;# mkdir abc<br/><br/>&#91;root@liyao home&#93;# ls<br/><br/>abc&nbsp;&nbsp;liyao<br/><br/>&#91;root@liyao home&#93;#<br/><br/> <br/></div><br/>我们在去 1.112 上去看下，abc 目录已经同步过来了<br/>[/code]<br/>[root@liyao home]# ll<br/><br/>total 8<br/><br/>drwxr-xr-x 2 root root 4096 Aug 21 04:12 abc<br/><br/>drwxr-xr-x 2 root root 4096 Aug 21 04:05 liyao<br/><br/>[root@liyao home]#<br/><br/> [/code]<br/><br/>OK ，这样我们就大功告成了。<br/><br/>=============================================<br/><br/>在主服务器上安装配置sresync<br/>在google code下载sersync的可执行文件版本，里面有配置文件与可执行文件，这里用sersync2.5进行说明，新版本配置形式类似。<br/><br/>1.在主服务器上开启sersync守护进程,使sersync在后台运行，开启实时同步。<br/><div class="code"><br/>./sersync -d<br/></div><br/>过程如下:<br/><div class="code"><br/>&#91;root@localhost GNU-Linux-x86&#93;# ls<br/>confxml.xml&nbsp;&nbsp;sersync2<br/>&#91;root@localhost GNU-Linux-x86&#93;# ./sersync2 -d<br/>set the system param<br/>execute：echo 50000000 &gt; /proc/sys/fs/inotify/max_user_watches<br/>execute：echo 327679 &gt; /proc/sys/fs/inotify/max_queued_events<br/>parse the command param<br/>daemon thread num: 10<br/>parse xml config file<br/>host ip : localhost&nbsp;&nbsp;&nbsp;&nbsp; host port: 8008<br/>config xml parse success<br/>please set /etc/rsyncd.conf max connections=0 Manually<br/>sersync working thread 12&nbsp;&nbsp;= 1(primary thread) + 1(fail retry thread) + 10(daemon sub threads)<br/>please according your cpu ，use -n param to adjust the cpu rate<br/>run the sersync:<br/>watch path is: /opt/tongbu<br/><br/></div><br/>表明，sersync已经开启，可以在本地监控路径下建立文件，查看远程是否同步成功。<br/> <br/>2.在开启实时监控的之前对主服务器目录与远程目标机目录进行一次整体同步<br/><div class="code"><br/>./sersync -r<br/></div><br/>如果需要将sersync运行前，已经存在的所有文件或目录全部同步到远程，要以-r参数运行sersync，将本地与远程整体同步一次。<br/>如果设置了过滤器，即在xml文件中，filter为true，则暂时不能使用-r参数进行整体同步。-r参数将会无效。<br/><br/>3.查看启动参数帮助<br/><div class="code"><br/>./sersync --help<br/></div><br/>4.指定配置文件<br/><div class="code"><br/>./sersync -o XXXX.xml<br/></div><br/>对于sersync使用可执行文件目录下的默认配置文件confxml.xml，如果需要使用另一个配置文件，可以使用－o参数指定其它配置文件。<br/><br/>5.指定默认的线程池的线程总数<br/><div class="code"><br/>./sersync -n num<br/></div><br/>例如 ./sersync -n 5 则指定线程总数为5，如果不指定，默认启动线程池数量是10，如果cpu使用过高，可以通过这个参数调低，如果机器配置较高，可以用－n跳高线程总数。<br/><br/>6.不进行同步，只运行插件<br/><div class="code"><br/>./sersync -m pluginName<br/></div><br/>例如./sersync -m command，则在监控到文件事件后，不对远程目标服务器进行同步，而是直接运行command插件。<br/><br/>7.多个参数可以配合使用<br/><div class="code"><br/>./sersync -n 8 -o abc.xml -r -d<br/></div><br/>表示，设置线程池工作线程为8个，指定abc.xml作为配置文件，在实时监控前作一次整体同步，以守护进程方式在后台运行。<br/><br/>8.通常情况下，对本地到远程整体同步一遍后，在后台运行实时同步。<br/><div class="code"><br/>./sersync -d<br/></div><br/><br/>sersync2 完全安装配置说明（二） —-可选功能与xml高级配置<br/><br/>XML文件说明<br/>sersync可选功能是通过xml配置文件来实现的，基本配置文件如下：<br/><div class="code"><br/><br/>&lt;?xml version=&quot;1.0&quot; encoding=&quot;ISO-8859-1&quot;?&gt;<br/> &lt;head version=&quot;2.5&quot;&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp; &lt;host hostip=&quot;localhost&quot; port=&quot;8008&quot;&gt;&lt;/host&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp; &lt;filter start=&quot;false&quot;&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;exclude expression=&quot;(.*)&#92;.gz&quot;&gt;&lt;/exclude&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;exclude expression=&quot;^info/*&quot;&gt;&lt;/exclude&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp; &lt;/filter&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp; &lt;inotify&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;delete start=&quot;true&quot;/&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;createFolder start=&quot;true&quot;/&gt;<br/>&lt;createFile start=&quot;true&quot;/&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp; &lt;/inotify&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp; &lt;debug start=&quot;false&quot;/&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp; &lt;sersync&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;localpath watch=&quot;/opt/tongbu&quot;&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;remote ip=&quot;192.168.0.104&quot; name=&quot;tongbu1&quot;/&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;!--&lt;remote ip=&quot;192.168.8.39&quot; name=&quot;tongbu&quot;/&gt;--&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;!--&lt;remote ip=&quot;192.168.8.40&quot; name=&quot;tongbu&quot;/&gt;--&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;/localpath&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;rsync&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;commonParams params=&quot;-artuz&quot;/&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;auth start=&quot;false&quot; users=&quot;root&quot; passwordfile=&quot;/etc/rsync.pas&quot;/&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;userDefinedPort start=&quot;false&quot; port=&quot;874&quot;/&gt;&lt;!-- port=874 --&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;timeout start=&quot;false&quot; time=&quot;100&quot;/&gt;&lt;!-- timeout=100 --&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;ssh start=&quot;false&quot;/&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;/rsync&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;failLog path=&quot;/tmp/rsync_fail_log.sh&quot; timeToExecute=&quot;60&quot;/&gt;&lt;!--default every 60min execute once--&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;crontab start=&quot;false&quot; schedule=&quot;600&quot;&gt;&lt;!--600mins--&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;crontabfilter start=&quot;false&quot;&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;exclude expression=&quot;*.gz&quot;&gt;&lt;/exclude&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;exclude expression=&quot;info/*&quot;&gt;&lt;/exclude&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;/crontabfilter&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;/crontab&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;plugin start=&quot;false&quot; name=&quot;command&quot;/&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp; &lt;/sersync&gt;<br/></div><br/>下面做逐行的进行解释说明：<br/><div class="code"><br/>&lt;host hostip=&quot;localhost&quot; port=&quot;8008&quot;&gt;&lt;/host&gt;<br/></div><br/>hostip与port是针对插件的保留字段，对于同步功能没有任何作用，保留默认即可。<br/><br/>filter文件过滤功能<br/>对于sersync监控的文件，会默认过滤系统的临时文件(以“.”开头，以“～”结尾)，除了这些文件外，可以自定义其他需要过滤的文件。<br/><div class="code"><br/>&lt;filter start=&quot;true&quot;&gt;<br/>&lt;exclude expression=&quot;(.*)&#92;.gz&quot;&gt;&lt;/exclude&gt;<br/>&lt;exclude expression=&quot;^info/*&quot;&gt;&lt;/exclude&gt;<br/>&lt;/filter&gt;<br/></div><br/>将start设置为 true，在exclude标签中，填写正则表达式，默认给出两个例子分别是过滤以”.gz”结尾的文件与过滤监控目录下的info路径（监控路径/info /*），可以根据需要添加，但开启的时候，自己测试一下，正则表达式如果出现错误，控制台会有提示。相比较使用rsync 的exclude功能，被过滤的路径，不会加入监控，大大减少rsync的通讯量。<br/><br/>inotify监控参数设定（优化）<br/>对于inotify监控参数可以进行设置，根据您项目的特点优化srsync。<br/><div class="code"><br/>&lt;inotify&gt;<br/>&lt;delete start=&quot;true&quot;/&gt;<br/>&lt;createFolder&nbsp;&nbsp;start=&quot;true&quot;/&gt;<br/>&lt;createFile start=&quot;true&quot;/&gt;<br/>&lt;/inotify&gt;<br/></div><br/>对于大多数应用，可以尝试把createFile（监控文件事件选项）设置为false来提高性能，减少 rsync通讯。因为拷贝文件到监控目录会产生create事件与close_write事件，所以如果关闭create事件，只监控文件拷贝结束时的事 件close_write，同样可以实现文件完整同步。<br/>注意：强将createFolder保持为true，如果将createFolder设为false，则不会对产生的目录进行监控，该目录下的子文件与子目录也不会被监控。所以除非特殊需要，请开启。默认情况下对创建文件（目录）事件与删除文件（目录）事件都进行监控，如果项目中不需要删除远程目标服务器的文件（目录），则可以将delete 参数设置为false，则不对删除事件进行监控。<br/><br/>Debug开启<br/><div class="code"><br/>&lt;debug start=&quot;false&quot;/&gt;<br/></div><br/>设置为true，开启debug模式，会在sersync正在运行的控制台，打印inotify事件与rsync同步命令。<br/><br/>XFS文件系统<br/><div class="code"><br/>&lt;fileSystem xfs=&quot;false&quot;/&gt;<br/></div><br/>对于xfs文件系统的用户，需要将这个选项开启，才能使sersync正常工作.<br/><br/>文件监控与远程同步设置<br/><div class="code"><br/>&lt;localpath watch=&quot;/opt/tongbu&quot;&gt;<br/>&lt;remote ip=&quot;192.168.0.104&quot; name=&quot;tongbu1&quot;/&gt;<br/>&lt;!--&lt;remote ip=&quot;192.168.8.39&quot; name=&quot;tongbu&quot;/&gt;--&gt;<br/>&lt;!--&lt;remote ip=&quot;192.168.8.40&quot; name=&quot;tongbu&quot;/&gt;--&gt;<br/>&lt;/localpath&gt;<br/></div><br/>详见sersync2 完全安装配置说明（一） —-基本功能使用<br/><br/>Rsync参数配置<br/><div class="code"><br/>&lt;rsync&gt;<br/>&lt;commonParams params=&quot;-artuz&quot;/&gt;<br/>&lt;auth start=&quot;false&quot; users=&quot;root&quot; passwordfile=&quot;/etc/rsync.pas&quot;/&gt;<br/>&lt;userDefinedPort start=&quot;false&quot; port=&quot;874&quot;/&gt;&lt;!-- port=874 --&gt;<br/>&lt;timeout start=&quot;false&quot; time=&quot;100&quot;/&gt;&lt;!-- timeout=100 --&gt;<br/>&lt;ssh start=&quot;false&quot;/&gt;<br/>&lt;/rsync&gt;<br/></div><br/>commonParams可以用户自定义rsync参数，默认是-artuz<br/>auth start=”false” 设置为true的时候，使用rsync的认证模式传送，需要配置user与passwrodfile(–password-file=/etc/rsync.pas)，来使用。userDefinedPort&nbsp;&nbsp;当远程同步目标服务器的rsync端口不是默认端口的时候使用(–port=874)。timeout设置rsync的timeout时间（–timeout=100）。ssh 使用rsync －e ssh的方式进行传输。<br/>失败日志脚步配置<br/><div class="code"><br/>&lt;failLog path=&quot;/tmp/rsync_fail_log.sh&quot; timeToExecute=&quot;60&quot;/&gt;<br/></div><br/>对于失败的传输，会进行重新传送，再次失败就会写入rsync_fail_log，然后每隔一段时间（timeToExecute进行设置）执行该脚本再次重新传送，然后清空该脚本。可以通过path来设置日志路径。<br/><br/>Crontab定期整体同步功能<br/><div class="code"><br/>&lt;crontab start=&quot;false&quot; schedule=&quot;600&quot;&gt;&lt;!--600mins--&gt;<br/>&lt;crontabfilter start=&quot;false&quot;&gt;<br/>&lt;exclude expression=&quot;*.gz&quot;&gt;&lt;/exclude&gt;<br/>&lt;exclude expression=&quot;info/*&quot;&gt;&lt;/exclude&gt;<br/>&lt;/crontabfilter&gt;<br/>&lt;/crontab&gt;<br/></div><br/>crontab可以对监控路径与远程目标主机每隔一段时间进行一次整体同步，可能由于一些原因两次失败重传都失败了，这个时候如果开启了crontab功 能，还可以进一步保证各个服务器文件一致，如果文件量比较大，crontab的时间间隔要设的大一些，否则可能增加通讯开销。schedule这个参数是设置crontab的时间间隔，默认是600分钟<br/>如果开启了filter文件过滤功能，那么crontab整体同步也需要设置过滤，否则虽然实时同步的时候文件被过滤了，但crontab整体同步的时候 如果不单独设置crontabfilter，还会将需过滤的文件同步到远程，crontab的过滤正则与filter过滤的不同，也给出了两个实例分别对 应与过滤文件与目录。总之如果同时开启了filter与crontab，则要开启crontab的crontabfilter，并按示例设置使其与filter的过滤一一对应。<br/><br/>插件设置<br/><div class="code"><br/>&lt;plugin start=&quot;false&quot; name=&quot;command&quot;/&gt;<br/></div><br/>当设置为true的时候，将文件同步到远程服务器后会调用name参数指定的插件。详见请看插件设置。<br/><br/><br/>sersync2 完全安装配置说明（三） —-插件基本配置和使用<br/><br/>插件相关xml<br/><br/><div class="code"><br/>&lt;sersync&gt;<br/>......<br/>&lt;plugin start=&quot;false&quot; name=&quot;command&quot;/&gt;<br/>&lt;/sersync&gt;<br/>&lt;plugin name=&quot;command&quot;&gt;<br/>&lt;param prefix=&quot;/bin/sh&quot; suffix=&quot;&quot; ignoreError=&quot;true&quot;/&gt;<br/>&lt;filter start=&quot;false&quot;&gt;<br/>&lt;include expression=&quot;(.*)&#92;.php&quot;/&gt;<br/>&lt;include expression=&quot;(.*)&#92;.sh&quot;/&gt;<br/>&lt;/filter&gt;<br/>&lt;/plugin&gt;<br/>&lt;plugin name=&quot;socket&quot;&gt;<br/>&lt;localpath watch=&quot;/opt/tongbu&quot;&gt;<br/>&lt;deshost ip=&quot;192.168.138.20&quot; port=&quot;8009&quot;/&gt;<br/>&lt;/localpath&gt;<br/>&lt;/plugin&gt;<br/>&lt;plugin name=&quot;refreshCDN&quot;&gt;<br/>&lt;localpath watch=&quot;/data0/htdocs/cms.xoyo.com/site/&quot;&gt;<br/>&lt;cdninfo domainname=&quot;ccms.chinacache.com&quot; port=&quot;80&quot; username=&quot;xxxx&quot; passwd=&quot;xxxx&quot;/&gt;<br/>&lt;sendurl base=&quot;http://pic.xoyo.com/cms&quot;/&gt;<br/>&lt;regexurl regex=&quot;false&quot; match=&quot;cms.xoyo.com/site(&#91;/a-zA-Z0-9&#93;*).xoyo.com/images&quot;/&gt;<br/>&lt;/localpath&gt;<br/>&lt;/plugin&gt;<br/></div><br/>如上面的xml所示，其中plugin标签设置为true时候，在同步文件或路径到远程之后后，调用插件。通过name参数指定需要执行的插件。目前支持的有command refreshCDN socket http四种插件。http插件目前由于兼容性原因去除，以后会重新加入。<br/><br/>以下模块（command refreshCDN http socket）可以单独使用（发生文件改变不同步只调用插件），只需在命令行下使用-m 参数即可。如果需要作为插件与同步程序一起使用，见同步程序说明的插件配置。<br/><br/>command插件<br/>当文件同步完成后，会调用command插件，如同步文件是test.php，则test.php文件在改动之后，调用rsync同步到远程服务器后，调用command插件，执行<br/><div class="code"><br/>/bin/sh test.php&nbsp;&nbsp;suffix &gt;/dev/null 2&gt;&amp;1<br/></div><br/>如果suffix 设置了，则会放在inotify事件test.php之后<br/>如果ignoreError为true，则会添加>/dev/null 2>&1<br/>当然还可以设置command的filter，当filter为ture，include可以只对正则匹配到的文件，调用command。<br/><br/>“refreshCDN”，就在同步过程中将文件发送到目 的服务器后刷新cdn接口。如果不想使用，则将start属性设为false即可。如果需要使用其他插件，则查看其他plugin标签，将插件名称改为 xml中其它插件的名称即可。该模块根据chinaCDN的协议，进行设计，当有文件产生的时候，就向cdn接口发送需要刷新的路径位置。刷新CDN模块需要配置的xml文件如下。<br/><div class="code"><br/>&lt;plugin name=&quot;refreshCDN&quot;&gt;<br/>&lt;localpath watch=&quot;/data0/htdocs/cms.xoyo.com/site/&quot;&gt;<br/>&lt;cdninfo domainname=&quot;ccms.chinacache.com&quot; port=&quot;80&quot; username=&quot;xxxx&quot; passwd=&quot;xxxx&quot;/&gt;<br/>&lt;sendurl base=&quot;http://pic.xoyo.com/cms&quot;/&gt;<br/>&lt;regexurl regex=&quot;false&quot; match=&quot;cms.xoyo.com/site(&#91;/a-zA-Z0-9&#93;*).xoyo.com/images&quot;/&gt;<br/>&lt;/localpath&gt;<br/>&lt;/plugin&gt;<br/></div><br/>其中 localpath watch 是需要监控的目录。<br/><br/>cdnifo标签制定了cdn接口的域名，端口号，以及用户名与密码。<br/><br/>sendurl标签是需要刷新的url的前缀。<br/><br/>regexurl标签中的，regex属性为true时候，使用match属性的正则语句匹配inotify返回的路径信息，并将正则匹配到的部分作为url一部分，<br/><br/>举例：<br/><br/>如果产生文件事件为：/data0/htdoc/cms.xoyo.com/site/jx3.xoyo.com/image/a/123.txt<br/><br/>经过上面的match正则匹配后，最后刷新的路径是:<br/><br/><a href="http://pic.xoyo.com/cms/jx3/a/123.txt;" target="_blank">http://pic.xoyo.com/cms/jx3/a/123.txt;</a><br/><br/>如果regex属性为false，最后刷新的路径是<br/><br/><a href="http://pic.xoyo.com/cms/jx3.xoyo.com/images/a/123.txt;" target="_blank">http://pic.xoyo.com/cms/jx3.xoyo.com/images/a/123.txt;</a><br/><br/>socket插件<br/>socket插件，开启该模块，则向指定ip与端口发送inotify所产生的文件路径信息。<br/><br/>Http插件<br/>http插件，可以向指定域名的主机post,inotify监控的事件。<br/><br/><br/><br/>单独运行插件<br/><br/>插件也可以单独使用，即不对远程目标机进行同步，直接调用插件:<br/><br/>只调用command插件<br/><div class="code"><br/>./sersync -d -m command<br/></div><br/>只调用refreshCDN插件<br/><div class="code"><br/>./sersync -d -m refreshCDN<br/></div><br/>只调用socket插件<br/><div class="code"><br/>./sersync -d -m socket<br/></div><br/>只调用http插件<br/><div class="code"><br/>./sersync -d -m http<br/></div><br/><br/>Tags - <a href="http://www.dzhope.com/tags/sersync/" rel="tag">sersync</a> , <a href="http://www.dzhope.com/tags/rsync/" rel="tag">rsync</a>
]]>
</description>
</item><item>
<link>http://www.dzhope.com/post//#blogcomment</link>
<title><![CDATA[[评论] sersync2 实时同步]]></title> 
<author> &lt;user@domain.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Thu, 01 Jan 1970 00:00:00 +0000</pubDate> 
<guid>http://www.dzhope.com/post//#blogcomment</guid> 
<description>
<![CDATA[ 
	
]]>
</description>
</item>
</channel>
</rss>