zoukankan      html  css  js  c++  java
  • nfs+sersync实时同步

    1.1 nfs01主机配置

    1.1.1 安装rsync服务

    1.安装rsync

    [root@nfs ~]# yum install rsync -y

    2.配置rsync

    #创建密码表

    [root@nfs01 ~]# echo "123456" > /etc/rsync.password

    [root@nfs01 ~]# chmod 600 /etc/rsync.password

    3.启动rsync

    #启动rsync服务,并加入自动启

    [root@nfs01 ~]# systemctl start rsyncd

    [root@nfs01 ~]# systemctl enable rsyncd

    Created symlink from /etc/systemd/system/multi-user.target.wants/rsyncd.service to /usr/lib/systemd/system/rsyncd.service.

    [root@nfs01 ~]# systemctl is-enabled rsyncd

    enabled

    [root@nfs01 ~]# systemctl status rsyncd

    ● rsyncd.service - fast remote file copy program daemon

       Loaded: loaded (/usr/lib/systemd/system/rsyncd.service; enabled; vendor preset: disabled)

       Active: active (running) since Sat 2018-07-28 14:59:38 CST; 23s ago

     Main PID: 1253 (rsync)

       CGroup: /system.slice/rsyncd.service

               └─1253 /usr/bin/rsync --daemon --no-detach

     

    Jul 28 14:59:38 nfs01 systemd[1]: Started fast remote file copy program daemon.

    Jul 28 14:59:38 nfs01 systemd[1]: Starting fast remote file copy program daemon...

    Jul 28 14:59:38 nfs01 rsyncd[1253]: rsyncd version 3.1.2 starting, listening on port 873

    4.创建文件测试推送服务

    [root@nfs01 ~]# touch 123

    [root@nfs01 ~]# rsync -avz /root/123 rsync_backup@172.16.1.41::backup/ --password-file=/etc/rsync.password

    sending incremental file list

    123

     

    sent 85 bytes  received 43 bytes  256.00 bytes/sec

    total size is 0  speedup is 0.00

    #检测结果

    [root@backup backup]# ls

    123

     

     

    1.1.1.1   安装sersync

    1.下载安装

    #创建软件存放目录

    [root@nfs01 2018-07-28]# mkdir /server/tools -p

    [root@nfs01 2018-07-28]# cd /server/tools/

    #下载

    [root@nfs01 tools]# wget https://raw.githubusercontent.com/wsgzao/sersync/master/sersync2.5.4_64bit_binary_stable_final.tar.gz

    [root@nfs01 tools]# tar xf sersync2.5.4_64bit_binary_stable_final.tar.gz

    [root@nfs01 tools]# mv GNU-Linux-x86/ /usr/local/sersync

    [root@nfs01 tools]# cd /usr/local/sersync/

    [root@nfs01 sersync]# cp confxml.xml confxml.bak                        #备份源文件

    2.配置sersync

    [root@nfs01 sersync]# vim 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="true"/>

        <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="true"/>

        <closeWrite start="true"/>

        <moveFrom start="true"/>

        <moveTo start="true"/>

        <attrib start="false"/>

        <modify start="false"/>

        </inotify>

     

        <sersync>

        <localpath watch="/data/www">

            <remote ip="172.16.1.41" name="nfs"/>

            <!--<remote ip="192.168.8.39" name="tongbu"/>-->

            <!--<remote ip="192.168.8.40" name="tongbu"/>-->

        </localpath>

        <rsync>

            <commonParams params="-az"/>

            <auth start="true" users="rsync_backup" passwordfile="/etc/rsync.password"/>

            <userDefinedPort start="false" port="874"/><!-- port=874 -->

            <timeout start="true" time="100"/><!-- timeout=100 -->

            <ssh start="false"/>

        </rsync>

        <failLog path="/tmp/rsync_fail_log.sh" timeToExecute="60"/><!--default every 60mins execute once-->

        <crontab start="false" schedule="600"><!--600mins-->

            <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"/>  <!--prefix /opt/tongbu/mmm.sh suffix-->

        <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.启动

    #查询帮助

    [root@nfs01 sersync]# ./sersync2 -help

    set the system param

    execute:echo 50000000 > /proc/sys/fs/inotify/max_user_watches

    execute:echo 327679 > /proc/sys/fs/inotify/max_queued_events

    parse the command param

    _______________________________________________________

    参数-d:启用守护进程模式

    参数-r:在监控前,将监控目录与远程主机用rsync命令推送一遍

    c参数-n: 指定开启守护线程的数量,默认为10个

    参数-o:指定配置文件,默认使用confxml.xml文件

    参数-m:单独启用其他模块,使用 -m refreshCDN 开启刷新CDN模块

    参数-m:单独启用其他模块,使用 -m socket 开启socket模块

    参数-m:单独启用其他模块,使用 -m http 开启http模块

    不加-m参数,则默认执行同步程序

    ________________________________________________________________

    #执行脚本

    [root@nfs01 sersync]# /usr/local/sersync/sersync2 -dro /usr/local/sersync/confxml.xml

    #检查结果

    [root@nfs01 sersync]# cd /data/www && rsync -az -R --delete ./  --timeout=100 rsync_backup@172.16.1.41::nfs --password-file=/etc/rsync.password

  • 相关阅读:
    Castle IOC容器内幕故事(下)
    Castle IOC容器实践之TypedFactory Facility(一)
    Castle ActiveRecord学习实践(9):使用ActiveRecord的一些技巧
    Web2.0改变了我的生活
    Castle IOC容器与Spring.NET配置之比较
    Castle IOC容器实践之Startable Facility(二)
    Castle IOC容器构建配置详解(二)
    Castle IOC容器实践之TypedFactory Facility(二)
    Castle IOC容器快速入门
    Castle IOC容器组件生命周期管理
  • 原文地址:https://www.cnblogs.com/wangkaiok/p/11943788.html
Copyright © 2011-2022 走看看