六狼论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博账号登陆

只需一步,快速开始

搜索
查看: 105|回复: 0

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

[复制链接]

升级  79.33%

45

主题

45

主题

45

主题

秀才

Rank: 2

积分
169
 楼主| 发表于 2013-2-4 13:31:19 | 显示全部楼层 |阅读模式
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.lock[web1]path=/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([/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"/>,即使不用,也不能删除掉,否则语法可以检测通过,但不能启动 
 
您需要登录后才可以回帖 登录 | 立即注册 新浪微博账号登陆

本版积分规则

快速回复 返回顶部 返回列表