天天看點

sersync2 實時同步配置

在同步伺服器上開啟sersync,将監控路徑中的檔案同步到目标伺服器,是以需要在同步伺服器配置sersync,在同步目标伺服器配置rsync。

一、同步目标伺服器配置rsync

# rpm -qa |grep rsync 

rsync-2.6.8-3.1 

# rpm -e rsync-2.6.8-3.1

unistall系統自帶安裝的rsync,安裝3.0版的rsync

# wget -c http://rsync.samba.org/ftp/rsync/rsync-3.0.8.tar.gz 

# tar xf rsync-3.0.8.tar.gz

# ./configure --prefix=/usr && make && make install

# vi /etc/rsyncd.conf

添加下面的代碼到rsyncd.conf中

uid = nobody 

gid = nobody 

use chroot = no 

strict modes = yes 

max connections = 200 

pid file = /var/run/rsyncd.pid 

lock file = /var/run/rsync.lock 

log file = /var/log/rsyncd.log 

[test] 

path = /home/

comment = test 

read only = no 

write only = no 

ignore errors = yes 

list = yes 

uid = root 

gid = root 

啟動rsync服務

# rsync --daemon 

二、配置sersync2

sersync2是金山逍遙網技術支援部平台組周洋童鞋,開發的一款基于 inotify + rsync 的大量檔案的多伺服器自動同步程式,目前已開源,開源協定為 New BSD License,項目的下載下傳位址:

http://code.google.com/p/sersync/ 

這個配置超簡單的,下載下傳檔案,解壓即可

# wget -c http://sersync.googlecode.com/files/sersync2.5_64bit_binary_stable_final.tar.gz 

# tar xf sersync2.5_64bit_binary_stable_final.tar.gz 

# cd GNU-Linux-x86 

# mkdir /etc/sersync2 

# cp confxml.xml /etc/sersync2 

# cp sersync2 /usr/bin 

配置sersync2

<sersync> 

        <localpath watch="/data/bb"> 

            <remote ip="192.168.1.4" name="test"/> 

            <remote ip="192.168.1.6" name="test"/> 

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

        </localpath> 

        <rsync> 

            <commonParams params="-artuz"/> 

            <auth start="false" users="root" passwordfile="/etc/rsync.pas"/> 

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

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

            <ssh start="false"/> 

        </rsync> 

        <failLog path="/var/log/rsync_fail.log" 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> 

表明要将同步伺服器上本地的/data/bb 路徑下的檔案,同步到遠端伺服器 192.168.1.4 與 192.168.1.6上的test 子產品下。

接下來,運作sersync2 

-r的意義

-r 在開啟實時監控之前對同步伺服器目錄與遠端目标機目錄進行一次整體同步 

運作完了輸出

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 

option: -r      rsync all the local files to the remote servers before the sersync work 

option: -d      run as a daemon 

option: -o      config xml name:  /etc/sersync2/confxml.xml 

daemon thread num: 10 

parse xml config file 

host ip : localhost     host port: 8008 

daemon start,sersync run behind the console 

config xml parse success 

please set /etc/rsyncd.conf max connections=0 Manually 

sersync working thread 112  = 1(primary thread) + 1(fail retry thread) + 10(daemon sub threads) 

Max threads numbers is: 32 = 12(Thread pool nums) + 20(Sub threads) 

please according your cpu ,use -n param to adjust the cpu rate 

------------------------------------------ 

rsync the directory recursivly to the remote servers once 

working please wait... 

execute command: cd /data/bb && rsync -artuz -R --delete ./ 192.168.1.4::test >/dev/null 2>&1 

run the sersync: 

watch path is: /data/bb 

sersync2的參數

sersync2 -h 

_______________________________________________________ 

參數-d:啟用守護程序模式 

參數-r:在監控前,将監控目錄與遠端主機用rsync指令推送一遍 

c參數-n: 指定開啟守護線程的數量,預設為10個 

參數-o:指定配置檔案,預設使用confxml.xml檔案 

參數-m:單獨啟用其他子產品,使用 -m refreshCDN 開啟重新整理CDN子產品 

參數-m:單獨啟用其他子產品,使用 -m socket 開啟socket子產品 

參數-m:單獨啟用其他子產品,使用 -m http 開啟http子產品 

不加-m參數,則預設執行同步程式 

________________________________________________________________ 

索性一次性運作

#  sersync2 -r -d -o /etc/sersync2/confxml.xml

其他功能待研究中

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