XML文件說明
sersync可選功能是通過xml配置文件來實現的,基本配置文件如下:
復制代碼 代碼如下:
<?xml version="1.0" encoding="ISO-8859-1"?>
<head version="2.5">
<host hostip="localhost" port="8008"></host>
<filter start="false">
<exclude expression="(.*)\.gz"></exclude>
<exclude expression="^info/*"></exclude>
</filter>
<inotify>
<delete start="true"/>
<createFolder start="true"/>
<createFile start="true"/>
</inotify>
<debug start="false"/>
<sersync>
<localpath watch="/opt/tongbu">
<remote ip="192.168.0.104" 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 60min execute once-->
<crontab start="false" schedule="600"><!--600mins-->
<crontabfilter start="false">
<exclude expression="*.gz"></exclude>
<exclude expression="info/*"></exclude>
</crontabfilter>
</crontab>
<plugin start="false" name="command"/>
</sersync>
下面做逐行的進行解釋說明:
復制代碼 代碼如下:
<host hostip="localhost" port="8008"></host>
hostip與port是針對插件的保留字段,對于同步功能沒有任何作用,保留默認即可。
filter文件過濾功能
對于sersync監控的文件,會默認過濾系統的臨時文件(以“.”開頭,以“~”結尾),除了這些文件外,可以自定義其他需要過濾的文件。
復制代碼 代碼如下:
<filter start="true">
<exclude expression="(.*)\.gz"></exclude>
<exclude expression="^info/*"></exclude>
</filter>
將start設置為 true,在exclude標簽中,填寫正則表達式,默認給出兩個例子分別是過濾以”.gz”結尾的文件與過濾監控目錄下的info路徑(監控路徑/info /*),可以根據需要添加,但開啟的時候,自己測試一下,正則表達式如果出現錯誤,控制臺會有提示。相比較使用rsync 的exclude功能,被過濾的路徑,不會加入監控,大大減少rsync的通訊量。
inotify監控參數設定(優化)
對于inotify監控參數可以進行設置,根據您項目的特點優化srsync。
復制代碼 代碼如下:
<inotify>
<delete start="true"/>
<createFolder start="true"/>
<createFile start="true"/>
</inotify>
對于大多數應用,可以嘗試把createFile(監控文件事件選項)設置為false來提高性能,減少 rsync通訊。因為拷貝文件到監控目錄會產生create事件與close_write事件,所以如果關閉create事件,只監控文件拷貝結束時的事 件close_write,同樣可以實現文件完整同步。
注意:強將createFolder保持為true,如果將createFolder設為false,則不會對產生的目錄進行監控,該目錄下的子文件與子目錄也不會被監控。所以除非特殊需要,請開啟。默認情況下對創建文件(目錄)事件與刪除文件(目錄)事件都進行監控,如果項目中不需要刪除遠程目標服務器的文件(目錄),則可以將delete 參數設置為false,則不對刪除事件進行監控。
Debug開啟
復制代碼 代碼如下:
<debug start="false"/>
設置為true,開啟debug模式,會在sersync正在運行的控制臺,打印inotify事件與rsync同步命令。
XFS文件系統
<fileSystem xfs="false"/>
對于xfs文件系統的用戶,需要將這個選項開啟,才能使sersync正常工作.
文件監控與遠程同步設置
復制代碼 代碼如下:
<localpath watch="/opt/tongbu">
<remote ip="192.168.0.104" name="tongbu1"/>
<!--<remote ip="192.168.8.39" name="tongbu"/>-->
<!--<remote ip="192.168.8.40" name="tongbu"/>-->
</localpath>
詳見sersync2 完全安裝配置說明(一) —-基本功能使用
Rsync參數配置
復制代碼 代碼如下:
<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>
commonParams可以用戶自定義rsync參數,默認是-artuz
auth start=”false” 設置為true的時候,使用rsync的認證模式傳送,需要配置user與passwrodfile(–password-file=/etc/rsync.pas),來使用。userDefinedPort 當遠程同步目標服務器的rsync端口不是默認端口的時候使用(–port=874)。timeout設置rsync的timeout時間(–timeout=100)。ssh 使用rsync -e ssh的方式進行傳輸。
失敗日志腳步配置
復制代碼 代碼如下:
<failLog path="/tmp/rsync_fail_log.sh" timeToExecute="60"/>
對于失敗的傳輸,會進行重新傳送,再次失敗就會寫入rsync_fail_log,然后每隔一段時間(timeToExecute進行設置)執行該腳本再次重新傳送,然后清空該腳本。可以通過path來設置日志路徑。
Crontab定期整體同步功能
復制代碼 代碼如下:
<crontab start="false" schedule="600"><!--600mins-->
<crontabfilter start="false">
<exclude expression="*.gz"></exclude>
<exclude expression="info/*"></exclude>
</crontabfilter>
</crontab>
crontab可以對監控路徑與遠程目標主機每隔一段時間進行一次整體同步,可能由于一些原因兩次失敗重傳都失敗了,這個時候如果開啟了crontab功 能,還可以進一步保證各個服務器文件一致,如果文件量比較大,crontab的時間間隔要設的大一些,否則可能增加通訊開銷。schedule這個參數是設置crontab的時間間隔,默認是600分鐘
如果開啟了filter文件過濾功能,那么crontab整體同步也需要設置過濾,否則雖然實時同步的時候文件被過濾了,但crontab整體同步的時候 如果不單獨設置crontabfilter,還會將需過濾的文件同步到遠程,crontab的過濾正則與filter過濾的不同,也給出了兩個實例分別對 應與過濾文件與目錄。總之如果同時開啟了filter與crontab,則要開啟crontab的crontabfilter,并按示例設置使其與filter的過濾一一對應。
插件設置
復制代碼 代碼如下:
<plugin start="false" name="command"/>
當設置為true的時候,將文件同步到遠程服務器后會調用name參數指定的插件。詳見請看插件設置。