且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

centos7安装sersync2+rsync+inotify-tools实现文件实时同步

更新时间:2021-08-03 17:52:44

服务器准备:

A:100.251.70.190 (客户图片文件的上传)从A同步到B

B:100.251.70.191 (客服浏览器浏览下载)

C:100.251.70.192 (客服浏览器浏览下载)

操作步骤:

(A和B服务器都必须安装的)

# rpm -qa|grep rsync

rsync-3.0.9-15.el7.x86_64

# yum install rsync(没有rsync就安装一下)

(B和C服务器安装配置)

vi /etc/rsyncd.conf

#工作中指定用户(需要指定用户)

uid = root

gid = root

#相当于黑洞.出错定位

use chroot = no

#有多少个客户端同时传文件

max connections = 200

#超时时间

timeout = 300

#进程号文件

pid file = /var/run/rsyncd.pid

#日志文件

lock file = /var/run/rsync.lock

#日志文件

log file = /var/log/rsyncd.log

#模块开始

#这个模块对应的是推送目录

#模块名称随便起

[tongbu]

#需要同步的目录

path = /opt/uploads

#表示出现错误忽略错误

ignore errors

#表示网络权限可写(本地控制真正可写)

read only = false

#这里设置IP或让不让同步

list = false

#指定允许的网段

hosts allow = 100.251.70.190

#拒绝链接的地址,以下表示没有拒绝的链接。

hosts deny = 0.0.0.0/32

#不要动的东西(默认情况)

#虚拟用户

auth users = root

#虚拟用户的密码文件

secrets file = /etc/rsync.password


配置访问账号密码

vi /etc/rsync.password

root:123456789

chmod 600 /etc/rsync.password


启动rsync 服务

rsync --daemon

ps -ef|grep rsync

netstat -tnulp|grep rsync


(A服务器安装配置)

配置访问账号密码

vi /etc/rsync.password

123456789

chmod 600 /etc/rsync.password


启动rsync 服务

rsync --daemon

ps -ef|grep rsync

netstat -tnulp|grep rsync


cd /opt

tar -zxvf sersync2.5.4_64bit_binary_stable_final.tar.gz

mv GNU-Linux-x86 /opt/sersync2

vi /opt/sersync2/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/uploads">

            <remote ip="100.251.70.191" name="tongbu"/>

            <remote ip="100.251.70.192" name="tongbu"/>

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

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

        </localpath>

        <rsync>

            <commonParams params="-artuz"/>

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

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

            <timeout start="false" 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>

# cd /opt/sersync2

# ./sersync2 -d

# ps -ef|grep rsync

# rsync -avSH ./uploads/ root@100.251.70.191::tongbu

# rsync -avSH ./uploads/ root@100.251.70.191::tongbu




本文转自 guowang327 51CTO博客,原文链接:http://blog.51cto.com/guowang327/1784369,如需转载请自行联系原作者