- 接收端rsyncd搭建
- 推送端sersync2使用
安装
源码包D:\share\src\sersync2.tar.gz
tar -C /opt -xf sersync2.tar.gz
配置文件例子(红色字体的是需要看实际情况更改的)
<?xml version="1.0" encoding="ISO-8859-1"?>
<head version="2.5">
<host hostip="localhost" port="8008"></host>
<debug start="false"/>
<fileSystem xfs="false"/>
<filter start="false"> <!-- 开启过滤 需要开启计划任务 过滤内容需要一至 -->
<exclude expression="(.*)\.svn"></exclude>
<exclude expression="(.*)\.gz"></exclude>
<exclude expression="^info/*"></exclude>
<exclude expression="^static/*"></exclude>
</filter>
<inotify>
<delete start="false"/> <!-- 设为false 推送端删除文件 接收端不会删除 -->
<createFolder start="true"/> <!--创建文件夹同步 -->
<createFile start="true"/> <!-- 创建文件 -->
<closeWrite start="true"/> <!-- -->
<moveFrom start="true"/> <!-- -->
<moveTo start="true"/> <!-- -->
<attrib start="false"/>
<modify start="false"/>
</inotify>
<sersync>
<localpath watch="/root/test"> <!-- 要推送内容所在路径 -->
<remote ip="192.168.55.51" name="test"/> <!--接收端ip 模块名 -->
<!--<remote ip="192.168.8.39" name="tongbu"/>-->
<!--<remote ip="192.168.8.40" name="tongbu"/>-->
</localpath>
<rsync>
<commonParams params="-avPz"/>
<auth start="true" users="test" passwordfile="/etc/rsync.password"/>
<userDefinedPort start="true" port="873"/><!-- port=874 -->
<timeout start="true" time="100"/><!-- timeout=100 -->
<ssh start="false"/>
</rsync>
<failLog path="/opt/sersync2/rsync_fail_log" timeToExecute="60"/><!--default every 60mins execute once-->
<crontab start="flase" schedule="60"><!--60mins 开启计划任务 不管有没有增加修改文件 都定时同步-->
<crontabfilter start="false"> <!--60mins -->
<exclude expression="*.php"></exclude>
<exclude expression="info/*"></exclude>
</crontabfilter>
</crontab>
<plugin start="false" name="command"/>
</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>
<plugin name="socket">
<localpath watch="/opt/tongbu">
<deshost ip="192.168.138.20" port="8009"/>
</localpath>
</plugin>
<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>
</head>
启动
nohup /opt/sersync2/sersync2 -r -d -o /opt/sersync2/test.xml &
启动参数说明
4.sersync启动参数说明
./sersync -r:-r参数作用是在开启实时监控的之前对主服务器目录与远程目标机目录进行一次整体同步。如果需要将sersync运行前,主服务器目录下已经存在的所有文件或目录全部同步到远端,则要以-r参数运行sersync,将本地与远程整体同步一次。特别说明:如果设置了过滤器,即在xml文件中,filter为true,则暂时不能使用-r参数进行整体同步。
./sersync –o old.xml:不指定-o参数时,sersync会使用sersync可执行文件目录下的默认配置文件confxml.xml,如果需要使用其他的配置文件,可以使用-o参数制定其它配置文件,通过-o参数,我们可以指定多个不同的配置文件,从而实现sersync多进程多实例的数据同步,本文的例子就是如此。
./sersync –n num:-n参数为指定默认的线程池的线程总数。例如: ./sersync –n 5 则指定线程总数为5,如果不指定,默认启动线程池数量是10,如果cpu使用过高,可以通过这个参数调低,如果机器配置较高,可以用-n调高默认的线程总数,提升同步效率。
./sersync –d:-d参数为后台启动服务,在通常情况下,使用-r参数对本地到远程整体同步一遍后,在后台运行此参数启动守护进程实时同步,在第一次整体同步时,-d和-r参数会联合使用。./sersync –d -r
./sersync –m plugnName:-m 参数为不进行同步,只运行插件
./sersync –m pluginName:例如:./sersync –m command,则在监控到事件后,不对远程目标服务器进行同步,而是直接运行command插件。
-n 8 –o sun.xml –r –d:多个参数可以配置使用,例如:./sersync –n 16 –o config.xml –r –d,表示设置线程池工作线程为16个,指定sun.xml作为配置文件,子实时监控前做一次整体同步,以守护进程方式在后台运行。通常情况下,首先要对本地到远程整体同步一遍之后,再在后台运行实时同步操作!