各主機IP
172.16.1.5 lb01
172.16.1.6 lb02
172.16.1.7 web02
172.16.1.8 web01
172.16.1.51 db01
172.16.1.31 nfs01
172.16.1.41 backup
172.16.1.61 m01
sersync主要用于服務器同步,web鏡像等功能。相當于之前我們使用的inotify-tools+rsync功能
sersync的優點
- 其是使用C++編寫,而且對Linux系統文件系統產生的臨時文件和重復的文件操作進行過濾,同步時效率更高花時更少.
- sersync配置簡單.
- 使用多線程進行同步,尤其在同步較大文件時能夠保證多個服務器實時保持同步狀態.
- 有出錯處理機制,通過失敗隊列對出錯的文件重新同步.
- 自帶crontab功能,只需要在xml配置文件中開啟
- 支持插件,二次開發的需要
sersync的使用(rsync客戶端主機上,本例是nfs01)
準備sersync軟件,點擊鏈接下載: sersync_64bit_binary_stable_final.tar.gz
tar -zxvf sersync_64bit_binary_stable_final.tar.gz -C /usr/local/sersync
里面有兩個文件
confxml.xml
配置文件
sersync2
二進制程序
SETP1:編輯配置文件confxml.xml
如下部分:
<filter start="false">
<exclude expression="(.*)\.svn"></exclude>
<exclude expression="(.*)\.gz"></exclude>
<exclude expression="^info/*"></exclude>
<exclude expression="^static/*"></exclude>
</filter>
<inotify>
<delete start="true"/>
<closeWrite start="true"/>
<moveFrom start="true"/>
<moveTo start="true"/>
<attrib start="false"/>
<modify start="false"/>
</inotify>
<sersync>
<localpath watch="/data">
<remote ip="172.16.1.41" name="nfsbkup"/>
<!--<remote ip="192.168.8.39" name="tongbu"/>-->
<!--<remote ip="192.168.8.40" name="tongbu"/>-->
</localpath>
<rsync>
<commonParams params="-avz"/>
<auth start="true" users="rsync_backup" passwordfile="/etc/rsync.password"/>
<userDefinedPort start="false" port="874"/><!-- port=874 -->
<timeout start="true" time="100"/><!-- timeout=100 -->
<ssh start="false"/>
</rsync>
<failLog path="/application/logs/rsync_fail_log.sh" timeToExecute="60"/><!--default ever
y 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>
remote ip即為rsync Server
name為rsync Server配置文件中指定的模塊名
auth 標簽里的user為rsync Server配置文件里指定的auth user
STEP2: 執行sersync
cd /usr/local/sersync
./sersync2 -o confxml.xml -n 10 -d
OK!!
sersync的參數說明:
-o: 指定使用的xml配置文件,默認使用confxml.xml文件
-n: 指定開啟守護線程的數量,默認為10個
-d:啟用守護進程模式
-m:單獨啟用其他模塊,
使用 -m refreshCDN 開啟刷新CDN模塊
使用 -m socket 開啟socket模塊
使用 -m http 開啟http模塊
加-m參數,則默認執行同步程序