xiaojiit 发表于 2013-2-4 13:31:19

使用sersync2 对Linux文件服务器进行同步

sersync主要用于服务器同步,web镜像等功能,采用Linux内核自带的inotify 机制,项目在Google的代码服务器上放着,可以去
 
http://code.google.com/p/sersync/ 下载最新的代码
 
由金山的周洋开发,他的博客地址:http://blog.johntechinfo.com/
 
在此,只做使用方法的介绍,主要参考:
 
http://blog.johntechinfo.com/technology/87
http://blog.johntechinfo.com/technology/96
 
1、测试环境
 
操作系统:CentOS5.6,
 
 
1、
rsync程序在系统安装完成后,已经自带,可以直接修改配置文件使用,但/etc/rsyncd.conf文件需要手工创建。
rsync服务端的配置代码/etc/rsyncd.conf:
 
uid=rootgid=rootmax connections=36000use chroot=nolog file=/var/log/rsyncd.logpid file=/var/run/rsyncd.pidlock file=/var/run/rsyncd.lockpath=/opt/web1comment=tongbu mu lu 1ignore errors=yesread only=nohosts allow=192.168.1.201/32hosts deny=* 
这里将hosts allow 设置为32位掩码的,确保只有指定的服务器可以同步到本服务器
2、
 
下载最新的sersync2,解压到/usr/bin目录下,会产生sersync2 和confxml.xml
 
sersync端的配置文件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="false"/>      <closeWrite start="true"/>      <moveFrom start="true"/>      <moveTo start="true"/>      <attrib start="false"/>      <modify start="false"/>    </inotify>    <sersync>      <localpath watch="/opt/web1">            <remote ip="192.168.1.200" name="web1"/>      </localpath>      <rsync>            <commonParams params="-artuz"/>            <auth start="false" users="tongbu" passwordfile="/etc/rsync.scrt"/>            <userDefinedPort start="false" port="8773"/>            <timeout start="false" time="100"/>            <ssh start="false"/>      </rsync>      <failLog path="/tmp/rsync_fail_log.sh" timeToExecute="60"/>      <crontab start="false" schedule="600">            <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"/>         <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(*).xoyo.com/images"/>      </localpath>    </plugin></head> 
 
3、首先启动rsync服务端的守护进行
 
#rsync --daemon
 
     之后,启动sersync2端的程序
 
 #sersync2 -o /etc/confxml.xml -r -d -n 20
 
 
4、现在在sersync2端监听目录里进行文件创建、修改、删除,会自动同步到rsync的服务器端。
 
  5、在<sersync></sersync>节点中的 <plugin start="false" name="command"/>,即使不用,也不能删除掉,否则语法可以检测通过,但不能启动 
 
页: [1]
查看完整版本: 使用sersync2 对Linux文件服务器进行同步