web服务器同步工具

来源:互联网 发布:幸运大转盘软件 编辑:程序博客网 时间:2024/05/05 06:42

sersync主要用于服务器同步,web镜像等功能。sersync是使用c++编写,在结合rsync同步的时候,节省了运行时耗和网络资源。因此更快。sersync配置起来很简单。另外本项目相比较其他脚本开源项目,使用多线程进行同步,尤其在同步较大文件时,能够保证多个服务器实时保持同步状态,同步及时快速。

  1. 安装环境
  2. 192.168.1.124  sersync服务器 
  3. 192.168.1.127  客户端 
  4. centos6 64bit 
  5.  
  6. 192.168.1.124 sersync服务器执行以下操作 
  7. 下载地址http://code.google.com/p/sersync/downloads/list 
  8. tar zxvf sersync2.5.4_64bit_binary_stable_final.tar.gz  -C /usr/bin  
  9. [root@localhost ~]# cd /usr/bin/GNU-Linux-x86/ 
  10. [root@localhost GNU-Linux-x86]# ls 
  11. confxml.xml  sersync2 
  12. vim confxml.xml
  13. <?xml version="1.0" encoding="ISO-8859-1"?> 
  14. <head version="2.5"> 
  15.     <host hostip="localhost" port="8008"></host> 
  16.     <debug start="false"/> 
  17.     <fileSystem xfs="false"/> 
  18.     <filter start="false"> 
  19.         <exclude expression="(.*)\.svn"></exclude> 
  20.         <exclude expression="(.*)\.gz"></exclude> 
  21.         <exclude expression="^info/*"></exclude> 
  22.         <exclude expression="^static/*"></exclude> 
  23.     </filter> 
  24.     <inotify> 
  25.         <delete start="true"/> 
  26.         <createFolder start="true"/> 
  27.         <createFile start="false"/> 
  28.         <closeWrite start="true"/> 
  29.         <moveFrom start="true"/> 
  30.         <moveTo start="true"/> 
  31.         <attrib start="false"/> 
  32.         <modify start="false"/> 
  33.     </inotify> 
  34.  #############################add 20120309###############################
  35. 对于大多数应用,可以尝试把createFile(监控文件事件选项)设置为false来提高性能,减少 rsync通讯。因为拷贝文件到监控目录会产生create事件与close_write事件,所以如果关闭create事件,只监控文件拷贝结束时的事 件close_write,同样可以实现文件完整同步。注意:强将createFolder保持为true,如果将createFolder设为false,则不会对产生的目录进行监控,该目录下的子文件与子目录也不会被监控。所以除非特殊需要,请开启。默认情况下对创建文件(目录)事件与删除文件(目录)事件都进行监控,如果项目中不需要删除远程目标服务器的文件(目录),则可以将delete 参数设置为false,则不对删除事件进行监控。
  36. 补充参考http://lihuipeng.blog.51cto.com/3064864/563291
  37. ###############################add 20120309##############################
  38.     <sersync> #黑体部分是我做的改动,其余没变要和客户端对应
  39.         <localpath watch="/opt/test"> 
  40.             <remote ip="192.168.1.127" name="test"/> 
  41.             <!--<remote ip="192.168.8.39" name="tongbu"/>--> 
  42.             <!--<remote ip="192.168.8.40" name="tongbu"/>--> 
  43.         </localpath> 
  44.         <rsync> 
  45.             <commonParams params="-artuz"/> 
  46.             <auth start="false" users="root" passwordfile="/etc/rsync.pas"/> 
  47.             <userDefinedPort start="false" port="874"/><!-- port=874 --> 
  48.             <timeout start="false" time="100"/><!-- timeout=100 --> 
  49.             <ssh start="false"/> 
  50.         </rsync> 
  51.         <failLog path="/tmp/rsync_fail_log.sh" timeToExecute="60"/><!--default every 60mins execute once--> 
  52.         <crontab start="false" schedule="600"><!--600mins--> 
  53.             <crontabfilter start="false"> 
  54.                 <exclude expression="*.php"></exclude> 
  55.                 <exclude expression="info/*"></exclude> 
  56.             </crontabfilter> 
  57.         </crontab> 
  58.         <plugin start="false" name="command"/> 
  59.     </sersync> 
  60.  
  61.     <plugin name="command"> 
  62.         <param prefix="/bin/sh" suffix="" ignoreError="true"/>  <!--prefix /opt/tongbu/mmm.sh suffix--> 
  63.         <filter start="false"> 
  64.             <include expression="(.*)\.php"/> 
  65.             <include expression="(.*)\.sh"/> 
  66.         </filter> 
  67.     </plugin> 
  68.  
  69.     <plugin name="socket"> 
  70.         <localpath watch="/opt/tongbu"> 
  71.             <deshost ip="192.168.138.20" port="8009"/> 
  72.         </localpath> 
  73.     </plugin> 
  74.     <plugin name="refreshCDN"> 
  75.         <localpath watch="/data0/htdocs/cms.xoyo.com/site/"> 
  76.             <cdninfo domainname="ccms.chinacache.com" port="80" username="xxxx" passwd="xxxx"/> 
  77.             <sendurl base="http://pic.xoyo.com/cms"/> 
  78.             <regexurl regex="false" match="cms.xoyo.com/site([/a-zA-Z0-9]*).xoyo.com/images"/> 
  79.         </localpath> 
  80.     </plugin> 
  81. </head> 
  82.  
  83.  安装 
  84. yum install rsync(sersync调用)  
  85.  
  86.  
  87. 192.168.1.127客户端 
  88. yum install rsync 
  89. [root@localhost test]# rpm -qa | grep rsync 
  90. rsync-3.0.6-5.el6_0.1.x86_64 
  91.  
  92. vi /etc/rsyncd.conf 
  93. uid=root 
  94. gid=root 
  95. max connections=100 
  96. use chroot=no 
  97. log file=/var/log/rsyncd.log 
  98. pid file=/var/run/rsyncd.pid 
  99. lock file=/var/run/rsyncd.lock 
  100. [test] #和sersync相关内容对应
  101. path=/opt/test 
  102. #uid = root     
  103. comment = test 
  104. ignore errors = yes 
  105. read only = no 
  106. hosts allow = 192.168.1.124 192.168.1.127 
  107.  
  108. 启动服务 
  109. rsync --daemon 
  110.  
  111. [root@localhost test]# ps -ef | grep rsync 
  112. root      1873     1  0 Dec06 ?        00:00:00 rsync --daemon 
  113. root      2818  1855  0 00:07 pts/0    00:00:00 grep rsync 
  114. [root@localhost test]# lsof -i:873 
  115. COMMAND  PID USER   FD   TYPE DEVICE SIZE/OFF NODE NAME 
  116. rsync   1873 root    4u  IPv4  11195      0t0  TCP *:rsync (LISTEN) 
  117. rsync   1873 root    5u  IPv6  11196      0t0  TCP *:rsync (LISTEN) 
  118.  
  119.  
  120. 然后 
  121. 192.168.1.124 sersync服务器执行以下操作启动服务 
  122. /usr/bin/GNU-Linux-x86/sersync2 -d -o /usr/bin/GNU-Linux-x86/confxml.xml 
  123. rsync --daemon 
  124.  
  125. [root@localhost GNU-Linux-x86]# ps -ef | grep rsync 
  126. root      1878     1  0 Dec06 ?        00:00:00 /usr/bin/GNU-Linux-x86/sersync2 -d -o /usr/bin/GNU-Linux-x86/confxml.xml 
  127. root      2543  1860  0 00:09 pts/0    00:00:00 grep rsync 
  128.  
  129. 然后说说我这两边的其他操作 我把selinux关了 iptables也关了   
  130.  
  131. 好了 现在可以测试去试试了
  132. ###################################################################
  133. 如果多台服务器到图片要同步到一台服务器,也就是rsync 同步一台服务器的多个目录
  134. 只需要在客户端多配置一个模块就行,以下为具体写法,test1,和test2分别为两个模块,test2为新加的,将另一台服务器的文件同步到另一个目录
  135. uid=root 
  136. gid=root 
  137. max connections=100 
  138. use chroot=no 
  139. log file=/var/log/rsyncd.log 
  140. pid file=/var/run/rsyncd.pid 
  141. lock file=/var/run/rsyncd.lock 
  142. [test1] #和sersync相关内容对应
  143. path=/opt/test 
  144. #uid = root     
  145. comment = test1
  146. ignore errors = yes 
  147. read only = no 
  148. hosts allow = 192.168.1.124
  149. [test2] #和sersync相关内容对应
  150. path=/opt/test2
  151. #uid = root     
  152. comment = test2
  153. ignore errors = yes 
  154. read only = no 
  155. hosts allow = 192.168.1.125
  156.  


原创粉丝点击