sersync原理是使用rsync命令推送同步的文件到rsync客户端。
优点是同步快,实时同步 使用资源少;
缺点是不只是双向实时同步,也就是说客户端新建文件不会同步到服务器端。
要实施双机实时同步的同学来说sersync不是一个好的办法。
sersync+rsync 客户端IP为192.168.16.130 服务器IP为192.168.16.128
实现目标:服务器端(推送端)/data/同步到客户端 /tmp/tongbu
客户端(只有rsync)配置
vi /etc/rsyncd.conf
mkdir /tmp/tongbu
vi /etc/rsync.pas
服务器端配置
vi /etc/rsync.pas
123456
chmod 600 /etc/rsync.pas
cd /usr/local/sersync/conf/
vi confxml.xml
<?xml version="1.0" encoding="ISO-8859-1"?>
<head version="2.5">
<host hostip="192.168.16.128" 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="true"/>
<createFolder start="true"/>
<createFile start="true"/>
<closeWrite start="true"/>
<moveFrom start="true"/>
<moveTo start="true"/>
<attrib start="true"/>
<modify start="true"/>
</inotify>
<sersync>
<localpath watch="/data"> # 要修改的
<remote ip="192.168.16.130" name="data"/> #要修改的
<!--<remote ip="192.168.8.39" name="tongbu"/>-->
<!--<remote ip="192.168.8.40" name="tongbu"/>-->
</localpath>
<rsync>
<commonParams params="-artuz"/>
<auth start="true" users="user" passwordfile="/etc/rsync.pas"/>#要修改的
<userDefinedPort start="false" port="873"/><!-- port=874 --> # 要修改的
<timeout start="false" time="100"/><!-- timeout=100 -->
<ssh start="false"/>
</rsync>
<failLog path="/tmp/rsync_fail_log.sh" timeToExecute="60"/><!--default every 60mins execute once-->
<crontab start="false" schedule="600"><!--600mins-->
<crontabfilter start="false">
<exclude expression="*.php"></exclude>
<exclude expression='#'" /*"></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>
使用命令:
killall sersync2 && sersync2 -r -d -o /usr/local/sersync/conf/confxml.xml