rsync+sersync大數據T級以上進行同步方法

操做系統:rhel 5.7 php

rsync地址: http://rsync.samba.org/download.html html

serync下載地址:https://sersync.googlecode.com/files/sersync2.5.4_64bit_binary_stable_final.tar.gz linux

此次的實驗主要有兩臺機器,172.16.54.114172.16.54.115,咱們把115作爲源服務器,114作爲目標服務器 c++

主要是把115/home/md中的全部數據實時同步到114上的/home/md express

1,先關閉防火牆 服務器

vi /etc/selinux/config #編輯防火牆配置文件 dom

#SELINUX=enforcing #註釋掉 ssh

#SELINUXTYPE=targeted #註釋掉 socket

SELINUX=disabled #增長 svn

:wq! #保存,退出

setenforce 0 #當即生效

 

2,查看端口是否被佔用(直接在命令行輸入)及安裝

netstat –apn | grep 873

 

安裝rsync,在兩臺服務器上都要進行這個步驟

首先將下載的包解壓

tar -xzvf  rsync-3.1.0.tar.gz

解壓後進入目錄

./configure --prefix=/usr/local/rsync

 

#說明安裝在/usr/local/rsync目錄中

在這一步以前要安裝相對就的gccgcc-c++

make

make install

安裝完畢

 

chkconfig rsync on #隨系統啓動

這個只在114上作

建立rsync配置文件rsync.conf

vi /etc/rsyncd.conf #建立配置文件,添加如下代碼

log file = /var/log/rsyncd.log #日誌文件位置,啓動rsync後自動產生這個文件,無需提早建立

pidfile = /var/run/rsyncd.pid  #pid文件的存放位置

lock file = /var/run/rsync.lock  #支持max connections參數的鎖文件

secrets file = /etc/rsync.pass  #用戶認證配置文件,裏面保存用戶名稱和密碼,後面會建立這個文件

motd file = /etc/rsyncd.Motd  #rsync啓動時歡迎信息頁面文件位置(文件內容自定義)

[md] #自定義名稱

path = /home/md/ #rsync服務端數據目錄路徑

comment = md #模塊名稱

uid = root #設置rsync運行權限爲root

gid = root #設置rsync運行權限爲root

port=873  #默認端口

use chroot = no #默認爲true,修改成no,增長對目錄文件軟鏈接的備份

read only = no  #設置rsync服務端文件爲讀寫權限

list = no #不顯示rsync服務端資源列表

max connections = 200 #最大鏈接數

timeout = 600  #設置超時時間

auth users = md #執行數據同步的用戶名,能夠設置多個,用英文狀態下逗號隔開

hosts allow = 172.16.54.114  #容許進行數據同步的客戶端IP地址,能夠設置多個,用英文狀態下逗號隔開

#hosts deny = 218.234.1.254 #禁止數據同步的客戶端IP地址,能夠設置多個,用英文狀態下逗號隔開(這個比較隨便,也能夠沒有)

:wq!  #保存,退出

 

建立用戶認證文件

vi /etc/rsync.scrt  #配置文件,添加如下內容

md:123456 #格式爲 用戶:密碼,若是是多個,能夠一行一個

:wq!  #保存,退出

chmod 600 /etc/rsyncd.conf  #設置文件全部者讀取、寫入權限

chmod 600 /etc/rsync.scrt  #設置文件全部者讀取、寫入權限

 

在此,咱們普及一個問題,咱們先進入/etc/xinetd.d文件中,能夠看到rsync這個文件,說明rsync是由xinetd管理,能夠經過xinetd來啓動rsync

/etc/init.d/xinetd start  #啓動

service xinetd stop   #中止

service xinetd restart #從新啓動

------------------------只在114上進行的到此爲止--------------------

 

如下只到115上進行

vi /etc/rsync.scrt  #編輯文件,添加如下內容

123456 #密碼

:wq! #保存退出

chmod 600 /etc/passwd.txt #設置文件權限,只設置文件全部者具備讀取、寫入權限便可

4,安裝sersync

上傳sersync2.5.4_64bit_binary_stable_final.tar.gz/usr/local目錄下

cd /usr/local

tar –xzvf  sersync2.5.4_64bit_binary_stable_final.tar.gz

這個解壓後會獲得一個GUN-linux x86的文件夾

mv G GUN-linux x86/*   /usr/local/sersync

cd  /usr/local/sersync #進入sersync安裝目錄

cp confxml.xml confxml.xml-bak  #備份原文件

vi 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="/home/md/">

<remote ip="172.16.54.114" name="buspos "/>

</localpath>

<rsync>

<commonParams params="-artuz"/>

<auth start="true" users="buspos" passwordfile="/etc/rsyncd.scrt"/>

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

#標紅的可按本身的配置改,名字和IP比較隨便,是個人配置,紅色#的還得根據本身rsync配置進行修改

 

 

5、設置sersync監控開機自動執行

vi /etc/rc.d/rc.local  #編輯,在最後添加一行

/usr/local/sersync/sersync2 -d -r -o  /usr/local/sersync/confxml.xml  #設置開機自動運行腳本

:wq!  #保存退出

 

寫完後,首先對數據進行一次總體同步

cd /usr/local/sersync

./sersync2 –r  #如下是輸入以後看到的

set the system param

execute錛歟cho 50000000 > /proc/sys/fs/inotify/max_user_watches

execute錛歟cho 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

daemon thread num: 10

parse xml config file

host ip : localhost     host port: 8008

Start the crontab       Every 600 minutes rsync all the files to the remote servers entirely

use rsync password-file :

user is buspos

passwordfile is         /etc/rsyncd.scrt

config xml parse success

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

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

Max threads numbers is: 22 = 12(Thread pool nums) + 10(Sub threads)

please according your cpu 錛寀se -n param to adjust the cpu rate

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

rsync the directory recursivly to the remote servers once

working please wait...

execute command: cd /home/md && rsync -artuz -R --delete ./ buspos@172.16.54.114::buspos --password-file=/etc/rsyncd.scrt >/dev/null 2>&1

run the sersync:

watch path is: /home/md

--------------------------------到此爲止-----------------------------

 

咱們來寫個簡單的腳本吧

vi  /home/sh/sersync.sh

#!/bin/sh

sersync="/usr/local/sersync/sersync2"

confxml="/usr/local/sersync/confxml.xml"

status=$(ps aux |grep 'sersync2'|grep -v 'grep'|wc -l)

if [ $status -eq 0 ];

then

$sersync -d -r -o $confxml &

else

exit 0;

fi

:wq    #保存腳本

 

vi /etc/crontab #編輯,在最後添加下面一行

*/5 * * * * root /home/sh/sersync.sh > /dev/null 2>&1  #每隔5分鐘執行一次腳本

service crond reload  #從新加載服務

至此就再也不管了,加入工做例程了!

相關文章
相關標籤/搜索