原創作品,允許轉載,轉載時請務必以超鏈接形式標明文章 原始出處 、作者信息和本聲明。否則將追究法律責任。http://nolinux.blog.51cto.com/4824967/1433623
在博文企業實時同步方案—-Sersync介紹中我們詳細介紹了Sersync的原理,設計架構以及和Inotify 等等的優勢區別。這里我就帶大家一起來做一下 Rsync +Sersync 這個同步分發架構案例。
實驗環境介紹:
內核版本:2.6.32-431.el6.x86_64 系統采用最小化安裝,系統經過了基本優化,selinux為關閉狀態,iptables為無限制模式 源碼包存放位置:/root Rsync客戶端+Sersync服務器(SERSYNC),承擔角色MASTER,IP:172.16.100.3,主機名:rsync-client-sersync SERSYNC_SLAVE,作為SERSYNC的從機,如果SERSYNC宕機,SERSYNC_SLAVE來接管服務,保證業務不中斷,本實驗不包括它! Web服務器A(即Rsync服務端)(SWEB1),承擔角色S1,IP:172.16.100.1,主機名:rsync-server-1 Web服務器B(即Rsync服務端)(SWEB2),承擔角色S2,IP:172.16.100.2,主機名:rsync-server-
[root@SWEB1 ~]# yum install rsync -y
[root@SWEB1 ~]# cat > /etc/rsyncd.conf << EOF #Rsync server #created by sunsky 00:17 2013-06-28 ##rsyncd.conf start## uid = root # rsync對后面模塊中的path路徑擁有什么權限 gid = root # rsync對后面模塊中的path路徑擁有什么權限 use chroot = no # 安全操作 max connections = 2000 # 定義連接數2000 timeout = 600 # 600秒超時 pid file = /var/run/rsyncd.pid lock file = /var/run/rsync.lock log file = /var/log/rsyncd.log ignore errors # 忽略錯誤 read only = false # false才能上傳文件,true不能上傳文件 list = false # 文件列表 hosts allow = 172.16.100.0/24 hosts deny = * auth users = rsync_bak # 虛擬用戶,同步時需要用這個用戶 secrets file = /etc/rsync.password # 密碼文件 ##################################### [web] # 模塊名稱 comment = redhat.sx site files by sunsky 00:17 2013-06-28 # 注釋 path = /data/web # 模塊的路徑 #################################### [download] comment = redhat.sx site sit data files by sunsky 00:17 2013-06-28 path = /data/download ##################################### EOF
[root@SWEB1 ~]# mkdir /data/{web,download} -p [root@SWEB1 ~]# tree /data /data ├── download └── web 2 directories, 0 files
[root@SWEB1 /]# echo 'rsync_bak:redhat' > /etc/rsync.password [root@SWEB1 /]# chmod 600 /etc/rsync.password [root@SWEB1 /]# cat /etc/rsync.password rsync_bak:redhat [root@SWEB1 /]# ll /etc/rsync.password -rw-------. 1 root root 7 Jun 4 00:20 /etc/rsync.password
[root@SWEB1 ~]# rsync --daemon
[root@SWEB1 /]# lsof -i tcp:873 COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME rsync 20982 root 3u IPv4 88170 0t0 TCP *:rsync (LISTEN) rsync 20982 root 5u IPv6 88171 0t0 TCP *:rsync (LISTEN)
[root@SWEB1 /]# echo "# rsyncd service daemon by sun 20140702" >>/etc/rc.local [root@SWEB1 /]# echo "/usr/bin/rsync --daemon" >> /etc/rc.local [root@SWEB1 /]# grep daemon /etc/rc.local # rsyncd service daemon by sun 20140702 /usr/bin/rsync --daemon
[root@SWEB1 /]# pkill rsync [root@SWEB1 /]# rsync --daemon
[root@SERSYNC /]# yum install rsync -y [root@SERSYNC /]# echo "redhat" > /etc/rsync.password [root@SERSYNC /]# chmod 600 /etc/rsync.password [root@SERSYNC /]# cat /etc/rsync.password Redhat [root@SERSYNC ~]# ll /etc/rsync.password -rw-------. 1 root root 7 Jun 4 00:20 /etc/rsync.password
[root@SERSYNC ~]# mkdir /data/{web,download} -p [root@SERSYNC ~]# touch /data/{web/index.html,download/a.jpg} [root@SERSYNC ~]# tree /data /data ├── download │ └── a.jpg └── web └── index.html 2 directories, 2 files
[root@SERSYNC ~]# rsync -avzP /data/web rsync_bak@172.16.100.1::web/ --password-file=/etc/rsync.password sending incremental file list web/ web/index.html 0 100% 0.00kB/s 0:00:00 (xfer#1, to-check=0/2) sent 92 bytes received 31 bytes 246.00 bytes/sec total size is 0 speedup is 0.00 [root@SERSYNC ~]# rsync -avzP /data/download/ rsync_bak@172.16.100.1::download/ --password-file=/etc/rsync.password sending incremental file list ./ a.jpg 0 100% 0.00kB/s 0:00:00 (xfer#1, to-check=0/2) sent 75 bytes received 30 bytes 210.00 bytes/sec total size is 0 speedup is 0.00
[root@SERSYNC ~]# rsync -avzP /data/web rsync_bak@172.16.100.2::web/ --password-file=/etc/rsync.password sending incremental file list web/ web/index.html 0 100% 0.00kB/s 0:00:00 (xfer#1, to-check=0/2) sent 92 bytes received 31 bytes 246.00 bytes/sec total size is 0 speedup is 0.00 [root@SERSYNC ~]# rsync -avzP /data/download/ rsync_bak@172.16.100.2::download/ --password-file=/etc/rsync.password sending incremental file list ./ a.jpg 0 100% 0.00kB/s 0:00:00 (xfer#1, to-check=0/2) sent 75 bytes received 30 bytes 70.00 bytes/sec total size is 0 speedup is 0.00
[root@SWEB1 ~]# tree /data/ /data/ ├── download │ └── a.jpg └── web └── web └── index.html 3 directories, 2 files
[root@SERSYNC ~]# mkdir /source/ [root@SERSYNC ~]# cd /source/ [root@SERSYNC ~]# wget https://sersync.googlecode.com/files/sersync2.5.4_64bit_binary_stable_final.tar.gz [root@SERSYNC source]# tar zxvf sersync2.5.4_64bit_binary_stable_final.tar.gz GNU-Linux-x86/ GNU-Linux-x86/sersync2 GNU-Linux-x86/confxml.xml
[root@SERSYNC source]# cp -r GNU-Linux-x86 /usr/local/sersync [root@SERSYNC source]# tree /usr/local/sersync /usr/local/sersync ├── confxml.xml └── sersync2 0 directories, 2 files
[root@SERSYNC source]# cd /usr/local/sersync [root@SERSYNC sersync]# mkdir conf bin logs [root@SERSYNC sersync]# mv confxml.xml conf [root@SERSYNC sersync]# mv sersync2 bin/sersync [root@SERSYNC sersync]# tree . ├── bin │ └── sersync ├── conf │ └── confxml.xml └── logs 3 directories, 2 files
[root@SERSYNC sersync]# cat conf/confxml.xml -n
<?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/tongbu"> <remote ip="127.0.0.1" name="tongbu1"/> <!--<remote ip="192.168.8.39" name="tongbu"/>--> <!--<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="/tmp/rsync_fail_log.sh" timeToExecute="60"/><!--default every 60mins ecute 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 ffix--> <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>
<localpathwatch="/opt/tongbu"> #定義本地要同步的目錄 <remoteip="127.0.0.1" name="tongbu1"/> # <!--<remoteip="192.168.8.39" name="tongbu"/>--> #同步到哪個機器,,同步到機器的哪個模塊 <!--<remoteip="192.168.8.40" name="tongbu"/>--> </localpath>
<localpathwatch="/data/web"> <remoteip="172.16.100.1" name="web"/> #這里取掉了兩旁的注釋 <remoteip="172.16.100.2" name="web"/> #這里取掉了兩旁的注釋 </localpath> 該文件中分隔符形式為:<!--###########################-->
<commonParamsparams="-artuz"/> <auth start="false"users="root" passwordfile="/etc/rsync.pas"/> <userDefinedPortstart="false" port="874"/><!-- port=874 --> <timeoutstart="false" time="100"/><!-- timeout=100 --> <sshstart="false"/>
<commonParamsparams="-aruz"/> <auth start="true"users="rsync_bak"passwordfile="/etc/rsync.password"/> <userDefinedPortstart="false" port="874"/><!-- port=874 --> <timeoutstart="true" time="100"/><!-- timeout=100 --> <sshstart="false"/>
rsync -aruz --timeout=100 /data/web rsync_bak@172.16.100.1::www/ --password-file=/etc/rsync.password
<failLogpath="/tmp/rsync_fail_log.sh"timeToExecute="60"/><!--default every 60mins execute once-->
[root@SERSYNC sersync]# cat -n /usr/local/sersync/conf/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="/data/web"> <remote ip="172.16.100.1" name="web"/> <remote ip="172.16.100.2" name="web"/> </localpath> <rsync> <commonParams params="-aruz"/> <auth start="true" users="rsync_bak" passwordfile="/etc/rsync.password"/> <userDefinedPort start="false" port="874"/><!-- port=874 --> <timeout start="true" time="100"/><!-- timeout=100 --> <ssh start="false"/> </rsync> <failLog path="/usr/local/logs/rsync_fail_log.sh" timeToExecute="60"/><!--default every mins 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 ffix--> <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>
[root@SERSYNC sersync]# cp /usr/local/sersync/conf/confxml.xml /usr/local/sersync/conf/download_confxml.xml
23 <sersync> 24<localpath watch="/data/download"> 25 <remote ip="172.16.100.1" name="download"/> 26 <remote ip="172.16.100.2" name="download"/> 27</localpath> 28<rsync>
[root@SERSYNC sersync]# echo 'export PATH=$PATH:/usr/local/sersync/bin'>>/etc/profile [root@SERSYNC sersync]# tail -1 /etc/profile export PATH=$PATH:/usr/local/sersync/bin [root@SERSYNC sersync]# . /etc/profile [root@SERSYNC sersync]# which sersync /usr/local/sersync/bin/sersync
[root@SERSYNC ~]# ls /usr/local/sersync/conf/* /usr/local/sersync/conf/confxml.xml /usr/local/sersync/conf/confxml.xml.bak.2014-06-04 /usr/local/sersync/conf/download_confxml.xml [root@SERSYNC ~]# sersync -r -d -o /usr/local/sersync/conf/confxml.xml 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: /usr/local/sersync/conf/confxml.xml daemon thread num: 10 parse xml config file host ip : localhosthost port: 8008 daemon start,sersync run behind the console use rsync password-file : user isrsync_bak passwordfile is /etc/rsync.password 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: 32 = 12(Thread pool nums) + 20(Sub threads) please according your cpu ,use -n param to adjust the cpu rate chmod: cannot access `/usr/local/logs/rsync_fail_log.sh': No such file or directory ------------------------------------------ rsync the directory recursivly to the remote servers once working please wait... execute command: cd /data/web && rsync -aruz -R --delete ./ --timeout=100 rsync_bak@172.16.100.1::web --password-file=/etc/rsync.password >/dev/null 2>&1 run the sersync: watch path is: /data/web [root@SERSYNC ~]# sersync -r -d -o /usr/local/sersync/conf/download_confxml.xml 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: /usr/local/sersync/conf/download_confxml.xml daemon thread num: 10 parse xml config file host ip : localhosthost port: 8008 daemon start,sersync run behind the console use rsync password-file : user isrsync_bak passwordfile is /etc/rsync.password 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: 32 = 12(Thread pool nums) + 20(Sub threads) please according your cpu ,use -n param to adjust the cpu rate chmod: cannot access `/usr/local/logs/rsync_fail_log.sh': No such file or directory ------------------------------------------ rsync the directory recursivly to the remote servers once working please wait... execute command: cd /data/download && rsync -aruz -R --delete ./ --timeout=100 rsync_bak@172.16.100.1::download --password-file=/etc/rsync.password >/dev/null 2>&1 run the sersync: watch path is: /data/download
[root@SERSYNC ~]# ps -ef |grep sersync root 2114 1 0 01:56 ? 00:00:00 sersync -r -d -o /usr/local/sersync/conf/confxml.xml root 2223 1 0 02:03 ? 00:00:00 sersync -r -d -o /usr/local/sersync/conf/download_confxml.xml root 2295 2244 0 02:08 pts/2 00:00:00 grep sersync
[root@SERSYNC ~]# cat >>/etc/rc.local<< 'EOF' > # sync data to 172.16.100.1,172.16.100.2 > sersync -d -o /usr/local/sersync/conf/confxml.xml > sersync -d -o /usr/local/sersync/conf/download_confxml.xml > EOF
[root@SERSYNC web]# for i in {1..10000};do echo 123456 > /data/web/$i &>/dev/null;done [root@SERSYNC web]# for i in {1..10000};do echo 123456 > /data/download/$i &>/dev/null;done [root@SERSYNC web]# tree /data/ /data/ ├── download │ ├── 1 ...... #中間信息省略 ...... #中間信息省略 ├── 9997 ├── 9998 ├── 9999 └── index.html 2 directories, 20001 files
[root@SERSYNC ~]# ps -ef |grep rsync|wc -l 52 [root@SERSYNC ~]# ps -ef |grep rsync|wc -l 63 [root@SERSYNC ~]# ps -ef |grep rsync|wc -l 20 [root@SERSYNC ~]# ps -ef |grep rsync|wc -l 83 [root@SERSYNC ~]# ps -ef |grep rsync|wc -l 83
[root@SERSYNC sersync]# cat conf/confxml.xml -n <?xml version="1.0" encoding="ISO-8859-1"?> <head version="2.5"> <host hostip="localhost" port="8008"></host> hostip與port是針對插件的保留字段,對于同步功能沒有任何作用,保留默認即可。 <debug start="false"/> 該行為Debug開啟開關。true為開啟debug模式,會在sersync正在運行的控制臺,打印 inotify 事件與 rsync 同步命令,生產環境一般不開啟。 <fileSystemfs="false"/>#對于XFS文件系統的用戶,需要將這個選項開啟,才能使sersync正常工作 對于sersync監控的文件,會默認過濾系統的臨時文件(以“開頭,以“~”結尾),除了這些文件外,在6-11行中,我們還可以自定義其它需要過濾的文件。 通過將 start 設置為 true 后可開啟過濾功能,在exclude標簽中可使用正則表達式。默認給出的兩個例子分別是過濾以“z”結尾的文件與過濾監控目錄下的info路徑(監控路徑/info/*),可以根據需求自己添加。但在開啟的時候,自己一定要測試下,如果正則表達式出現錯誤,控制臺會有相應提示。相比較使用 Rsync 的xclude 功能,被過濾的路徑,不會加入監控,大大減少 Rsync 同步的通訊量 <filter start="false"> <exclude expression="(.*)\.svn"></exclude> <exclude expression="(.*)\.gz"></exclude> <exclude expression="^info/*"></exclude> <exclude expression="^static/*"></exclude> </filter> 第123行用來定義 inotify 監控參數,我們可以根據項目的特點來優化 Sersync。 對多數應用,可以嘗試把 createFile(監控文件事件選項)設置為false來提高性能,進一步減少 Rsync通訊。因為拷貝文件到監控目錄會產生 create 事件與 close_write 事件,所以如果關閉create 事只監控文件拷貝結束時的事件 close_write,同樣可以實現文件完整同步。 注要使得 createFolder 保持為true,如果將createFolder設為false,則不會對產生的目錄進行監控,該下的子文件與子目錄也不會被監控,所以除非特殊需要,請開啟。默認情況下對創建文件(目錄)事件與文件(目錄)事件都進行監控,如果項目中不需要刪除遠程目標服務器的文件(目錄),則可以將 dele 參數設置為 false,則不對刪除事件進行監控。 <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> 第248行用來定義所要同步和監控的目錄文件。 /optongbu目錄為sersync主服務器本地待同步的目錄,ip=“192.168.8.39”為從服務器的ip地址,如果有多個器,依次列出來即可。name=“tongbu”,這里的tongbu為rsyncd.con的模塊名字,即中括號中的名稱。 <localpath watch="/opt/tongbu"> <remote ip="127.0.0.1" name="tongbu1"/> <!--<remote ip="192.168.8.39" name="tongbu"/>--> <!--<remote ip="192.168.8.40" name="tongbu"/>--> </localpath> 第295行用來定義rsync的命令參數 在 cmonParams 項,我們可以自定義rsync的同步參數,默認是-artuz,auth star“false”設置為true的時候,使用rsync的認證模式傳送,需要配置user與passwordfile(-password-fileetc/rsync.pas)來使用。userDefinedPort 當同步目標服務器的rsync端口不是默認端口的時候使用(-port74)。timeout設置rsync的timeout事件(-timeout=100)。<ssh start=”false”/>如啟表示ssh使用rsync -e ssh的方式進行傳輸。 <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> 第3用來定義失敗日志腳本配置 如件同步傳輸失敗,會重新傳送,再次失敗就會寫入 rsync_fail_log.sh,然后每隔一段時間(timeToExecute進行設置)執行該腳本再次重新傳送,然后清空該腳本??梢酝ㄟ^path來設置日志路徑 <failLog path="/tmp/rsync_fail_log.sh" timeToExecute="60"/><!--default every 60mins ecute once--> 第372行用來定義Crontab定期整體同步功能 Cronb可以對監控路徑與遠程目標主機每隔一段時間進行一次整體同步,可能由于一些原因兩次失敗重傳都失,這個時候如果開啟了 crontab 功能,還可以進行一次保證各個服務器文件一致,如果文件量比較大,crtab的時間間隔要設的大一些,否則可能增加通訊開銷,schedule這個參數是設置crontab的時間間隔,默600分鐘。 如啟了 filter 文濾功能,那么crontab整體同步也需要設置過濾,否則雖然實時同步的時候文件被過濾了,但 crontab 整步的時候,如果不單獨設置crontabfilter,還會將需過濾的文件同步到遠程從服務器,crontab的過濾正filter過濾的不同,也給出了兩個實例分別對應與過濾文件與目錄,總之如果同時開啟了filter與crontab,則要開啟crontab的crontabfilter,并按示例設置使其與filter的過濾一一對應。 <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> 從4到行尾,都是插件的相關信息。當plugin標簽設置為true時候,在同步文件或路徑到遠程服務器之后,會插件。通過name參數指定需要執行的插件。目前支持的有command、refreshCDN、socket、http四種插件中,http插件目前由于兼容性原因已經去除,以后會重新加入。 <plugin name="command"> <param prefix="/bin/sh" suffix="" ignoreError="true"/><!--prefix /opt/tongbu/mmm.sh ffix--> <filter start="false"> <include expression="(.*)\.php"/> <include expression="(.*)\.sh"/> </filter> </plugin> 第548行為插件socket的相關配置 sock插件,開啟該模塊,則向指定ip與端口發送inotify所產生的文件路徑信息 <plugin name="socket"> <localpath watch="/opt/tongbu"> <deshost ip="192.168.138.20" port="8009"/> </localpath> </plugin> 第595行為插件refreshCDN的相關配置 refrhCDN 用來在同步過程中將文件發送到目地服務器后,刷新cdn接口。如果不想使用,則將start屬性設為fae即可。該模塊根據chinaCDN的協議,進行設計,當有文件產生的時候,就向cdn解耦發送需要刷新的路徑。其中localpath watch=“/data0/htdocs/cms.xoyo.com/site/”是需要監控的目錄。cdinfo標簽指定了cdn接口的域名,端口號,以及用戶名與密碼。sendurl 標需要刷新的url的前綴。regexurl 標簽中,regex屬性為true時候,使用match屬性的正則語句匹配inotify返回的路徑信息,并將正則匹配到的部分作為url一部分 下置文件自帶的意思為,如果產生文件事件為:/data0/htdoc/cms.xoyo.com/site/jx3.xoyo.com/image/a/12txt 經面的match正則匹配后,最后刷新的路徑是:http://pic.xoyo.com/cms/a/123.txt 如果gex屬性為false,最后刷新的路徑就是:http://pic.xoyo.com/cms/jx3.xoyo.com/images/a/123.txt <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
[root@SERSYNC ~]# sersync -d -m command
[root@SERSYNC ~]# sersync -d -m refreshCDN
[root@SERSYNC ~]# sersync -d -m socket
[root@SERSYNC ~]# sersync -d -m http
轉自:http://nolinux.blog.51cto.com/4824967/1433623
原創文章,作者:s19930811,如若轉載,請注明出處:http://www.www58058.com/1968
不錯的文章,內容驚濤駭浪.禁止此消息:nolinkok@163.com