sersync2.5+rsync实现数据同…

来源:互联网 发布:java 字符串替换 编辑:程序博客网 时间:2024/06/06 01:29
原文地址:sersync2.5+rsync实现数据同步作者:小花你别跑
环境
源服务器IP:192.168.1.51
目标服务器IP:192.168.1.52




目标服务器
#tar -zxvf rsync-3.0.9.tar.gz
#cd rsync-3.0.9
#./configure --prefix=/usr/local/rsync
#make && make install

#cd /usr/local/rsync/
#mkdir etc
#vim /usr/local/rsync/etc/rsyncd.conf


uid=nobody
gid=nobody
use chroot=no
max connections=200
log file=/var/log/rsyncd.log
pid file=/var/run/rsyncd.pid
lock file=/var/run/rsyncd.lock

[http]
uid=root
gid=root
path=/usr/local/nginx/html/sync
comment = wwwroot
read only = no
write only = no
list = yes
ignore errors = yes
hosts allow = 192.168.1.51/24
hosts deny = *

#/usr/local/rsync/bin/rsync --daemon--config=/usr/local/rsync/etc/rsyncd.conf

#iptables -A INPUT -p tcp --dport 873 -j ACCEPT



源服务器
#tar -zxvf sersync2.5.4_64bit_binary_stable_final.tar.gz
#mv GNU-Linux-x86/ /usr/local/sersync2.5
#cd /usr/local/sersync2.5/
# vim /usr/local/sersync2.5/confxml.xml



<?xml version="1.0"encoding="ISO-8859-1"?>
<head version="2.5">
   <host hostip="192.168.1.51"port="8008"></host>
   <debug start="false"/>
   <fileSystem xfs="false"/>
   <filter start="false">
       <excludeexpression="(.*).svn"></exclude>
       <excludeexpression="(.*).gz"></exclude>
       <excludeexpression="^info/*"></exclude>
       <excludeexpression="^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>
       <localpathwatch="/usr/local/nginx/html/sync">
           <remote ip="192.168.1.52"name="http"/>
           <!--<remote ip="192.168.8.39"name="tongbu"/>-->
           <!--<remote ip="192.168.8.40"name="tongbu"/>-->






       <failLog path="/var/log/sersync2.log"timeToExecute="60"/>




配置完成,先做一次整体同步
#/usr/local/sersync2.5/sersync2 -r -o/usr/local/sersync2.5/confxml.xml


守护进程模式启动sersync2
#/usr/local/sersync2.5/sersync2 -d -o/usr/local/sersync2.5/confxml.xml









sersync2配置文件详解

<?xml version="1.0"encoding="ISO-8859-1"?>
<head version="2.5">
   <host hostip="localhost"port="9090"></host>
   <debug start="false"/>
   <fileSystem xfs="false"/>
   <filter start="true">
    <excludeexpression="^((?!original.).*)$"></exclude>   
                   #只备份源里面文件名是original开头的,后缀名不限定的文件,?!original 代表反向选择
    <!-- <excludeexpression="abc"></exclude>
    <excludeexpression="image"></exclude>
    <excludeexpression="txt"></exclude>
    <excludeexpression="xml"></exclude>
    <excludeexpression="*"></exclude>
    -->
   </filter>
   <inotify>
    <deletestart="false"/>                   #不监控文件或目录的删除
    <createFolderstart="true"/>       #监控目录的创建
    <modifystart="true"/>                   #监控文件的修改
    <createFilestart="true"/>              #监控创建新文件
    <closeWrite start="false"/>
    <moveFrom start="false"/>
    <moveTo start="false"/>
    <attrib start="false"/>
   </inotify>

   <sersync>
    <localpathwatch="/data/bookfm/doc/book">  #设置监控的目录
        <remote ip="192.168.100.250"name="book"/>  
                                                    
#指定目标主机的IP地址和模块名(和samba的类似,不是目录的名称)
                                                  
#有几台目标主机,配置这样几条,同时也要在目标上启用rsync守护进程
        <!--<remote ip="192.168.8.39"name="tongbu"/>-->
        <!--<remote ip="192.168.8.40"name="tongbu"/>-->
    </localpath>
    <rsync>
        <commonParamsparams="-au"/>  #指定rsync 运行时的参数,可根据自身需要更改
        <auth start="true" users="bookbackup"passwordfile="/usr/local/GNU-Linux-x86/rsyncd.secrets"/>
      #启用验证,指定用户名和密码文件(只用写一个密码即可)
      #用户名是目标服务器上rsync配置文件中指定的用户名,密码文件中的密码也目标服务器上rsync指定的密码文件指定的密码
        <userDefinedPort start="false"port="874"/><!-- port=874-->
        <timeout start="false"time="100"/><!-- timeout=100-->
        <ssh start="false"/>
    </rsync>
    <failLog path="/var/rsync/rsync_error.log"timeToExecute="60"/><!--default every60mins execute once-->
                                                                                                        #指定错误的日志文件路径
    <crontab start="false"schedule="600"><!--600mins-->
        <crontabfilter start="false">
         <excludeexpression="*.php"></exclude>
         <excludeexpression="info/*"></exclude>
        </crontabfilter>
    </crontab>
    <plugin start="false"name="command"/>
   </sersync>

   <plugin name="command">
    <param prefix="/bin/sh" suffix=""ignoreError="true"/>    <!--prefix /opt/tongbu/mmm.shsuffix-->
    <filter start="false">
        <includeexpression="(.*).php"/>
        <includeexpression="(.*).sh"/>
    </filter>
   </plugin>

   <plugin name="socket">
    <localpath watch="/opt/tongbu">
        <deshost ip="192.168.138.20"port="8009"/>
    </localpath>
   </plugin>
   <plugin name="refreshCDN">
    <localpathwatch="/data0/htdocs/cms.xoyo.com/site/">
        <cdninfo domainname="ccms.chinacache.com" port="80"username="xxxx" passwd="xxxx"/>
        <sendurlbase="http://pic.xoyo.com/cms"/>
        <regexurl regex="false"match="cms.xoyo.com/site([/a-zA-Z0-9]*).xoyo.com/images"/>
    </localpath>
   </plugin>
</head>
配置文件一般根据自己需要修改





0 0
原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 有限公司法人变更后债务怎么办 有限公司法人跑路债务怎么办 网上买票身份信息待核验怎么办 微信买票身份核验失败怎么办 买高铁票待核验怎么办 网上购票身份待核验怎么办 b站稿件版权原因怎么办 已离职老板打电话说账有问题怎么办 开到应急刹车道怎么办 自动挡的车刹车失灵怎么办 自动挡的车如果刹车失灵怎么办 手动挡汽车刹车失灵怎么办 车辆没有年检出了交通事故怎么办 跟着大货车闯了红灯怎么办 在万家金服买的电子产品坏了怎么办 汽车被油笔画了怎么办? 挂到别人车跑了怎么办 浪琴手表保修卡掉了怎么办 事故车辆维修和报废怎么办 4.2货车拉缸了怎么办 工作中与同事发生矛盾怎么办 和领导关系闹僵怎么办 内倒窗户卡住了怎么办 支付宝存在安全风险怎么办 地铁车站空调坏了怎么办 面试防汛值班发生灾情你怎么办 怀孕上班路途太远怎么办 硕士错过校招应该怎么办 收银员收多了钱怎么办 商铺贷款批不了怎么办 铁路局的门面乱收房租怎么办 酒店夜审房费多过怎么办 夜审房价录多了怎么办 做工地拿不到钱怎么办 赢了官司拿不到钱怎么办 工地上拿不到钱怎么办 做了工拿不到钱怎么办 高速公路上车没油了怎么办 高铁乘务员年龄大了怎么办 总公司跑路了分公司怎么办 坐车久了耳朵懵怎么办