rsync+sersync實現數據文件實時同步

一.簡介centos

sersync是基於Inotify開發的,相似於Inotify-tools的工具;服務器

sersync能夠記錄下被監聽目錄中發生變化的(包括增長、刪除、修改)具體某一個文件或某一個目錄的名字;ssh

rsync在同步的時候,只同步發生變化的這個文件或者這個目錄(每次發生變化的數據相對整個同步目錄數據來講是很小的,rsync在遍歷查找比對文件時,速度很快),所以,效率很高;工具

:當同步的目錄數據量不大時,建議使用Rsync+Inotify-tools;當數據量很大(幾百G甚至1T以上)、文件不少時,建議使用Rsync+sersync。測試

 

二.具體操做ui

操做系統:centos6.6
源服務器(sersync):192.168.0.1  --> 目標服務器(rsync):192.168.0.2

目的:使用root用戶,把源服務器上的/test1目錄下的文件實時同步到目標服務器的/test2目錄下google

 
(一)目標服務器(rsync):192.168.0.2
一、安裝rsync
yum -y install rsync
二、建立rsyncd.conf配置文件
vi /etc/rsyncd.conf
--------------------------
uid = root
gid = root
max connections = 10
log file = /var/log/rsyncd.log
pid file = /var/run/rsyncd.pid
lock file = /var/run/rsyncd.lock
 
[test]     #模塊自定義名稱 ---這個須要與源服務器Sersync對應
path = /test2 #須要同步到這個目錄
comment = Mirror to test
ignore errors = yes
use chroot = no  #默認爲true,修改成no,增長對目錄文件軟鏈接的備份
read only = no    #設置rsync服務端文件爲讀寫權限
hosts allow = 192.168.0.1 #容許訪問源服務器IP
hosts deny = 0.0.0.0/32 #拒絕全部IP鏈接,先容許後拒絕
exclude =/data1 /data2  不一樣步的目錄
 
:這裏只是列出一些配置項而已,其餘在配置時按需選擇。
------------------------------
三、啓動服務

/usr/bin/rsync --daemon /etc/rsyncd.confspa

(二)源服務器(sersync):192.168.0.1
一、安裝rsync
yum -y install rsync
二、同步數據

rsync -avzP /test1/ root@192.168.0.2::test/  測試同步文件操作系統

--/test1/ 同步目錄
--192.168.0.2 目的服務器,安裝並配置完畢rsync
--test 模塊自定義名稱,即目的服務器的rsync配置文件中配置的
三、安裝sersync工具,實時觸發rsync進行同步
#cd /usr/local/src

#wget https://sersync.googlecode.com/files/sersync2.5.4_64bit_binary_stable_final.tar.gzcode

 
#tar zxvf sersync2.5_32bit_binary_stable_final.tar.gz
    GNU-Linux-x86/
    GNU-Linux-x86/sersync2
    GNU-Linux-x86/confxml.xml
#mv /usr/local/src/GNU-Linux-x86/ /usr/local/sersync/
#vi /usr/local/sersync/confxml.xml
須要修改以下幾個地方:
<localpath watch="/data/test">
    <!—-設置監控的目錄-->
     <remote ip="192.168.0.2" name="test"/>
    <!—設置從服務器的IP-->
    <!--<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/rsyncd.secret"/>
    <!—-設置同步的用戶名和密碼文件-->
     <userDefinedPort start="true" port="873"/><!-- port=874 -->
    <!—-設置rsync的端口,要和從那邊開啓的端口一致-->
    <timeout start="false" time="100"/><!-- timeout=100 -->
    <ssh start="false"/>
</rsync>
 
注:若是目的服務器的rsync有配置帳號密碼時,這裏須要配置/etc/rsyncd.secret
四、啓動sersync

/usr/local/sersync/sersync2 -r -d -o /usr/local/sersync/confxml.xml

相關文章
相關標籤/搜索