Centos 6.3 x86_64 配置rsync+inotify

Centos 6.3 x86_64 配置rsync+inotify
一,inotify簡介
Inotiy是一種強大的,細粒度的,異步的文件系統事件監控機制,linux內核從2.6.13版本起,加入了對inotify的支持。通過對inotify可以監控文件系統中添加、刪除、修改、移動等各種細微事件,利用這個內核接口,第三方軟件可以監控文件系統下文件的各種變化情況。
目前有inotify-tools,google開源項目Openduckbill,還有一個sersync由金山周洋開發並開源的。在監控事件變化的效率比inotify-tools高,至於高多少,可以參數這個網址http://blog.johntechinfo.com/sersyncguild。
二,實驗效果圖

Server是一個內容發佈系統,後端採用負載均衡集羣部署方案,由一個負載調試節點,多臺服務節點組成。內容發佈系節點負責將用戶發佈的數據生成靜態頁面,同時將靜態網頁傳輸給3個服務節點,負載調試器將用戶請求根據負載算法調度到到相應的web節點上,實現用戶訪問。
三,配置serync,rsync配置參考http://bingodeng.blog.51cto.com/1038075/1180876
這裏只做一些簡單的修改,rsync使用系統自帶的,如果沒有可以使用yum安裝。
1,先對web節點配置好rsync,web節點配置都一樣
# vim /etc/rsyncd.conf 
uid=nobody
gid=nobody
use chroot=no
max connections=0
strict modes=yes
pid file=/var/run/rsyncd.pid
lock file=/var/run/rsyncd.lock
log file=/var/log/rsyncd.log
[test]
path=/data
comment=ixdba file
ignore errors
read only=no
write only=no
hosts allow =192.168.1.0/24
hosts deny=*
list=false
uid=root
gid=root
auth users=backup
secrets file=/etc/server.pass
# vim /etc/server.pass 
backup:ixdba123
#chmod 600 /e tc/server.pass
這次使用xinetd來控制rsync服務
#yum -y install xinetd
#chkconfig rsync on
#chkconfig xinetd on
#/etc/init.d/xinetd start
#netstat -tunlp |grep 873
tcp        0      0 :::873                      :::*        LISTEN     25340/xinetd 
2,配置sersync,配置比較簡單,一個xml格式的配置文件和一個可執行文件。
# vim /etc/server.pass 
ixdba123
#chmod 600 /etc/server.pass
#tar xf sersync2.5.4.tar.gz -C /usr/local
#cd /usr/localGNU-Linux-x86
#vim config.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="true">  #默認過慮是關閉的,如果想開啓改爲true
<exclude expression="(.*)\.svn"></exclude>
<exclude expression="(.*)\.gz"></exclude>
<exclude expression="^info/*"></exclude>
<exclude expression="^static/*"></exclude>
    </filter>
    <inotify>    #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="/var/www">   #對本機哪個目錄監控
    <remote ip="192.168.1.28" name="test"/>   #將/var/www目錄的文件同步到rsync 模塊test中,可以定義多個
    <!--<remote ip="192.168.8.39" name="tongbu"/>-->
    <!--<remote ip="192.168.8.40" name="tongbu"/>-->
</localpath>
<rsync>
    <commonParams params="-artuz"/>   #rsync命令同步的參數
    <auth start="true" users="backup" passwordfile="/etc/server.pass"/>  #同步的用戶與密碼文件
    <userDefinedPort start="false" port="874"/><!-- port=874 -->
    <timeout start="false" time="100"/><!-- timeout=100 -->
    <ssh start="false"/>
</rsync>
#錯誤日誌記錄在/tmp下
<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/p_w_picpaths"/>
</localpath>
    </plugin>
</head>
3,測試rsync配置有沒有問題
# rsync -avl /etc/fstab  [email protected]::test --password-file=/etc/server.pass
4,啓動sersync
./sersync2 -d 
5,寫入/etc/rc.local文件
echo "/usr/local/GNU_linux/sersync2 -d &">>/etc/rc.local
6,測試
在/var/www/目錄下建立文件和文件夾,觀察是否同步到web節點的/data目錄下
四,Serync2命令使用
1,查看幫助
./sersync2 -help 
2,指定別的配置文件
./sersync2 -o xxx.xml
3,指定默認的線程池的線程總數
./sersync -n num
./sersync -n 5 則指定線程總數爲5,如果不指定,默認啓動線程池數量是10,如果cpu使用過高,可以通過這個參數調低,如果機器配置較高,可以用-n跳高線程總數。
4,不進行同步,只運行插件
./sersync2-m pluginName
例如./sersync2 -m command,則在監控到文件事件後,不對遠程目標服務器進行同步,而是直接運行command插件。
5,多個參數可以配合使用
./sersync -n 8 -o abc.xml -r -d   
表示,設置線程池工作線程爲8個,指定abc.xml作爲配置文件,在實時監控前作一次整體同步,以守護進程方式在後臺運行。 如果配置文件開啓過濾的話,-r將不能使用。
6,通常情況下,對本地到遠程整體同步一遍後,在後臺運行實時同步。
./sersync -d
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章