您的位置:首页 > 运维架构 > Linux

sersync代替inotify实现服务器之间实时同步(CentOS 6.7)

2015-11-26 01:36 435 查看



注:
1)系统版本:CentOS 6.7 X86_642)已部署完成rsync服务(IP为:172.16.1.41)1、上传安装sersync
mkdir  -p /home/yongzhen/tools/
cd /home/yongzhen/tools/
rz -y
ll
tar xf sersync2.5_64bit_binary_stable_final.tar.gz
mv GNU-Linux-x86 /usr/local/sersync
cd /usr/local/sersync/
cp confxml.xml confxml.xml.base
ll confxml.xml.base
mkdir /backup -p
2、修改配置文件

[root@test sersync]# cat confxml.xml
<?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="true"/>
<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="/backup">
<remote ip="172.16.1.41" name="backup"/>
<!--<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="rsync_backup" passwordfile="/etc/rsync.password"/>
<userDefinedPort start="false" port="874"/><!-- port=874 -->
<timeout start="false" time="100"/><!-- timeout=100 -->
<ssh start="false"/>
</rsync>
<failLog path="/home/yongzhen/rsync_fail_log.sh" timeToExecute="60"/><!--default every 60mins execute once-->
<crontab start="true" schedule="600"><!--600mins-->
<crontabfilter start="false">
<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>

3、启动sersync
/usr/local/sersync/sersync2 -r -d -o /usr/local/sersync/confxml.xml
ll /home/yongzhen/
touch {1..10}简单测试一下同步
小结:
sersync的优点
1)sersync是使用c++编写,由于只同步发生更改的文件,因此比其他同步工具更节约时间、带宽;
2)安装方便、配置简单(有配置文件);
3)使用多线程进行同步,能够保证多个服务器实时保持同步状态;
4)自带出错处理机制,通过失败队列每隔60min对出错的文件重新出错,如果仍旧失败,则每10个小时对同步失败的文件重新同步;
5)自带crontab功能,只需在xml配置文件中开启,即可按要求,隔一段时间整体同步一次;
6)自带socket与http协议扩展,你可以方便的进行二次开发;
7)执行时自动优化内核参数
sersync的缺点
sersync有重传机制(内置的定时任务),但是只重传一次,如果重传失败就会清空重传队列,即清空/tmp/rsync_fail_log.sh文件。这样就会造成sersync服务恢复正常后(即可以同步文件),数据同步的两个服务器数据不一致的现象。因为,/tmp/rsync_fail_log.sh文件为空,而sersync只对发生变化的文件做实时同步(ps:sersync默认每隔十个小时做一次完整的数据同步)。

本文出自 “万越天的架构师之路” 博客,请务必保留此出处http://wanyuetian.blog.51cto.com/3984643/1716932
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: