rsync & sersync 实时同步
1、根据之前一篇关于rsync的随笔部署好rsync服务后,可以开始inotify的部署
2、sersync的部署
①、部署服务(安装和配置过程)
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#Master 部署Sersync服务 mkdir -p /home/jpinsz/tools cd /home/jpinsz/tools wget http://sersync.googlecode.com/files/sersync2.5.4_64bit_binary_stable_final.tar.gz #安装Sersync tar -zxvf sersync2.5.4_64bit_binary_stable_final.tar.gz -C /usr/local/ cd /usr/local mv GNU-Linux-x86 sersync #规范sersync目录结构 cd sersync/ mkdir conf bin logs mv confxml.xml conf mv sersync2 bin/sersync tree #配置sersync /bin/cp conf/confxml.xml conf/confxml.xml.jpinsz.$(data +%F) #初始的配置文件 [root@Centos6-Sersync-M1-11 sersync]# cat -n conf/confxml.xml 1 <?xml version="1.0" encoding="ISO-8859-1"?> 2 <head version="2.5"> 3 <host hostip="localhost" port="8008"></host> 4 <debug start="false"/> 5 <fileSystem xfs="false"/> 6 <filter start="false"> 7 <exclude expression="(.*)\.svn"></exclude> 8 <exclude expression="(.*)\.gz"></exclude> 9 <exclude expression="^info/*"></exclude> 10 <exclude expression="^static/*"></exclude> 11 </filter> 12 <inotify> 13 <delete start="true"/> 14 <createFolder start="true"/> 15 <createFile start="false"/> 16 <closeWrite start="true"/> 17 <moveFrom start="true"/> 18 <moveTo start="true"/> 19 <attrib start="false"/> 20 <modify start="false"/> 21 </inotify> 22 23 <sersync> 24 <localpath watch="/opt/tongbu"> 25 <remote ip="127.0.0.1" name="tongbu1"/> 26 <!--<remote ip="192.168.8.39" name="tongbu"/>--> 27 <!--<remote ip="192.168.8.40" name="tongbu"/>--> 28 </localpath> 29 <rsync> 30 <commonParams params="-artuz"/> 31 <auth start="false" users="root" passwordfile="/etc/rsync.pas"/> 32 <userDefinedPort start="false" port="874"/><!-- port=874 --> 33 <timeout start="false" time="100"/><!-- timeout=100 --> 34 <ssh start="false"/> 35 </rsync> 36 <failLog path="/tmp/rsync_fail_log.sh" timeToExecute="60"/><!--default every 60mins execute once--> 37 <crontab start="false" schedule="600"><!--600mins--> 38 <crontabfilter start="false"> 39 <exclude expression="*.php"></exclude> 40 <exclude expression="info/*"></exclude> 41 </crontabfilter> 42 </crontab> 43 <plugin start="false" name="command"/> 44 </sersync> 45 46 <plugin name="command"> 47 <param prefix="/bin/sh" suffix="" ignoreError="true"/> <!--prefix /opt/tongbu/mmm.sh suffix--> 48 <filter start="false"> 49 <include expression="(.*)\.php"/> 50 <include expression="(.*)\.sh"/> 51 </filter> 52 </plugin> 53 54 <plugin name="socket"> 55 <localpath watch="/opt/tongbu"> 56 <deshost ip="192.168.138.20" port="8009"/> 57 </localpath> 58 </plugin> 59 <plugin name="refreshCDN"> 60 <localpath watch="/data0/htdocs/cms.xoyo.com/site/"> 61 <cdninfo domainname="ccms.chinacache.com" port="80" username="xxxx" passwd="xxxx"/> 62 <sendurl base="http://pic.xoyo.com/cms"/> 63 <regexurl regex="false" match="cms.xoyo.com/site([/a-zA-Z0-9]*).xoyo.com/images"/> 64 </localpath> 65 </plugin> 66 </head> #优化sersync的配置: 1、修改24-28行的部分,原内容为: 24 <localpath watch="/opt/tongbu"> 25 <remote ip="127.0.0.1" name="tongbu1"/> 26 <!--<remote ip="192.168.8.39" name="tongbu"/>--> 27 <!--<remote ip="192.168.8.40" name="tongbu"/>--> 28 </localpath> 修改后内容为: <localpath watch="/data/www/www"> <remote ip="10.0.0.12" name="www"/> <remote ip="10.0.0.13" name="www"/> </localpath> <!--#################################--> <localpath watch="/data/www/bbs"> <remote ip="10.0.0.12" name="bbs"/> <remote ip="10.0.0.13" name="bbs"/> </localpath> <!--#################################--> <localpath watch="/data/www/blog"> <remote ip="10.0.0.12" name="blog"/> <remote ip="10.0.0.13" name="blog"/> </localpath> <!--#################################--> 2、修改31-34行,认证部分 原内容: 31 <auth start="false" users="root" passwordfile="/etc/rsync.pas"/> 32 <userDefinedPort start="false" port="874"/><!-- port=874 --> 33 <timeout start="false" time="100"/><!-- timeout=100 --> 34 <ssh start="false"/> 修改后内容为: <rsync> <commonParams params="-aruz"/> <auth start="true" users="rsync_backup" passwordfile="/etc/rsync.password"/> <userDefinedPort start="false" port="874"/><!-- port=874 --> <timeout start="true" time="100" /><!--timeout=100--> <ssh start="false"/> </rsync> 3、修改36-37行 36 <failLog path="/tmp/rsync_fail_log.sh" timeToExecute="60"/><!--default every 60mins execute once--> 修改后内容为: <failLog path="/usr/local/sersync/logs/rsync_fail_log.sh" timeToExecute="60"/><!--default every 60mins execute once-->
②、sersync启动命令
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#开启sersync守护进程同步数据 ##配置sersync环境变量 echo 'export PATH=$PATH:/usr/local/sersync/bin'>>/etc/profile tail -1 /etc/profile source /etc/profile which sersync #启动命令: sersync -r -d -o /usr/local/sersync/conf/confxml.xml #关闭命令: pkill sersync 多实例初始化同步命令: sersync -r -d -o /usr/local/sersync/conf/www_confxml.xml sersync -r -d -o /usr/local/sersync/conf/blog_confxml.xml sersync -r -d -o /usr/local/sersync/conf/bbs_confxml.xml /bin/cp /etc/rc.local /etc/rc.local_$(date +%F) cat >>/etc/rc.local<<EOF #sync date to 12 13 sersync -d -o /usr/local/sersync/conf/www_confxml.xml sersync -d -o /usr/local/sersync/conf/blog_confxml.xml sersync -d -o /usr/local/sersync/conf/bbs_confxml.xml EOF