`
xiaojiit
  • 浏览: 129051 次
  • 性别: Icon_minigender_2
  • 来自: 北京
社区版块
存档分类
最新评论

使用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=root
gid=root
max connections=36000
use chroot=no
log file=/var/log/rsyncd.log
pid file=/var/run/rsyncd.pid
lock file=/var/run/rsyncd.lock

[web1]
path=/opt/web1
comment=tongbu mu lu 1
ignore errors=yes
read only=no
hosts allow=192.168.1.201/32
hosts 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([/a-zA-Z0-9]*).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
2
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics