天天看點

centos7安裝sersync2+rsync+inotify-tools實作檔案實時同步

伺服器準備:

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伺服器安裝配置)

123456789

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

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

</head>

# cd /opt/sersync2

# ./sersync2 -d

# ps -ef|grep rsync

# rsync -avSH ./uploads/ [email protected]::tongbu

本文轉自 guowang327 51CTO部落格,原文連結:http://blog.51cto.com/guowang327/1784369,如需轉載請自行聯系原作者

繼續閱讀