一:環境
操做系統環境:redhat6.6php
內核版本:2.6.32-358.el6.x86_64html
rsync server:192.168.2.3(部署rsync server)express
rsync client:192.168.2.4(部署sersync)dom
特別說明:ssh
我以前用rsync進行生產環境數據的同步,因爲目錄下每日會有上千個文件生成,因此目錄自己就比較大,用rsync的進行無差別同步的時候發現就掃描目錄的文件就須要很長時間,同步效率有些低,後面用inotify+rsync進行數據同步,有個問題是:inotify監控目錄文件變化的時候,在咱們要對生產系統進行開啓或關閉的時候,因爲目錄佔用問題致使開啓或關閉生產組件會出現進程沒關閉的顯示,可是其實是關閉了的,因爲檢查進程的時候發現目錄被佔用了;因此今天用sersync進行數據同步的時候發現速度快了好多,因此留個筆記之後方便查看。socket
二:sersync部署
一、下載sersync安裝包
連接:https://pan.baidu.com/s/1kHQSVEODxbtXpxxMnT1S2A
提取碼:9q4msvn
二、解壓安裝包
[root@rsync_client tools]# tar xf sersync2.5.4_64bit_binary_stable_final.tar.gz
[root@rsync_client tools]# mv GNU-Linux-x86 /usr/local/sersync
三、備份原配置文件
[root@rsync_client ~]# cd /usr/local/sersync/ [root@rsync_client sersync]# cp confxml.xml confxml.xml.ori
四、部署rsync server詳細參數解釋請看https://www.cnblogs.com/zhangweiyi/p/10571152.html
1 [root@rsync_server ~]# cat /etc/rsyncd.conf 2 uid = rsync 3 gid = rsync 4 use chroot = no 5 max connections = 200 6 timeout = 300 7 pid file = /var/run/rsyncd.pid 8 lock file = /var/run/rsync.lock 9 log file = /var/log/rsyncd.log 10 ignore errors 11 read only = false 12 list = false 13 hosts allow = 192.168.2.0/24 14 hosts deny = 0.0.0.0/32 15 auth users = sam 16 secrets file = /etc/rsync.password 17 [test] 18 path = /tmp/
五、配置rsync密碼文件
[root@rsync_server ~]# cat /etc/rsync.password sam:test123 [root@rsync_server ~]# [root@rsync_server ~]# ll /etc/rsync* # 查看文件權限是否爲600 -rw------- 1 root root 364 Nov 30 08:29 /etc/rsyncd.conf-rw------- 1 root root 13 Nov 21 09:59 /etc/rsync.password
六、啓動rsync
[root@rsync_server ~]# rsync --daemon [root@rsync_server ~]# lsof -i :873 COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME rsync 1206 root 3u IPv4 11197 0t0 TCP *:rsync (LISTEN) rsync 1206 root 5u IPv6 11198 0t0 TCP *:rsync (LISTEN)
三:部署sersync
一、首先建立rsync server端的密碼驗證文件
[root@rsync_client ~]# cat /etc/rsync.password test123 [root@rsync_client ~]# ll /etc/rsync.password # 確保文件權限爲600 -rw-------. 1 root root 7 11月 26 19:53 /etc/rsync.password
二、部署sersync
[root@rsync_client tools]# tar xf sersync2.5.4_64bit_binary_stable_final.tar.gz [root@rsync_client tools]# mv GNU-Linux-x86 /usr/local/sersync [root@rsync_client sersync]# cp confxml.xml confxml.xml.ori [root@rsync_client sersync]#
三、修改config.xml文件只修改我註釋了的便可
1 [root@rsync_client sersync]# cat confxml.xml 2 <?xml version="1.0" encoding="ISO-8859-1"?> 3 <head version="2.5"> 4 <host hostip="localhost" port="8008"></host> 5 <debug start="false"/> 6 <fileSystem xfs="false"/> 7 <filter start="false"> 8 <exclude expression="(.*)\.svn"></exclude> 9 <exclude expression="(.*)\.gz"></exclude> 10 <exclude expression="^info/*"></exclude> 11 <exclude expression="^static/*"></exclude> 12 </filter> 13 <inotify> 14 <delete start="true"/> 15 <createFolder start="true"/> 16 <createFile start="true"/> # 修改此項爲true 17 <closeWrite start="true"/> 18 <moveFrom start="true"/> 19 <moveTo start="true"/> 20 <attrib start="false"/> 21 <modify start="false"/> 22 </inotify> 23 24 <sersync> 25 <localpath watch="/tmp/"> # 監控的目錄 26 <remote ip="192.168.2.4" name="test"/> # 須要把監控的目錄數據同步到rsync server指定的模塊下,前面寫了server的模塊名是test對應的目錄是:/tmp/ 27 <!--<remote ip="192.168.8.39" name="tongbu"/>--> 28 <!--<remote ip="192.168.8.40" name="tongbu"/>--> 29 </localpath> 30 <rsync> 31 <commonParams params="-artuz"/> 32 <auth start="true" users="sam" passwordfile="/etc/rsync.password"/> # 指定rsync的虛擬用戶和密碼文件路徑 33 <userDefinedPort start="false" port="874"/><!-- port=874 --> 34 <timeout start="false" time="100"/><!-- timeout=100 --> 35 <ssh start="false"/> 36 </rsync> 37 <failLog path="/var/log/rsync_fail_log.sh" timeToExecute="60"/><!--default every 60mins execute once--> # 把日誌文件的路徑改到/var/log/下 38 <crontab start="false" schedule="600"><!--600mins--> 39 <crontabfilter start="false"> 40 <exclude expression="*.php"></exclude> 41 <exclude expression="info/*"></exclude> 42 </crontabfilter> 43 </crontab> 44 <plugin start="false" name="command"/> 45 </sersync> 46 47 <plugin name="command"> 48 <param prefix="/bin/sh" suffix="" ignoreError="true"/> <!--prefix /opt/tongbu/mmm.sh suffix--> 49 <filter start="false"> 50 <include expression="(.*)\.php"/> 51 <include expression="(.*)\.sh"/> 52 </filter> 53 </plugin> 54 55 <plugin name="socket"> 56 <localpath watch="/opt/tongbu"> 57 <deshost ip="192.168.138.20" port="8009"/> 58 </localpath> 59 </plugin> 60 <plugin name="refreshCDN"> 61 <localpath watch="/data0/htdocs/cms.xoyo.com/site/"> 62 <cdninfo domainname="ccms.chinacache.com" port="80" username="xxxx" passwd="xxxx"/> 63 <sendurl base="http://pic.xoyo.com/cms"/> 64 <regexurl regex="false" match="cms.xoyo.com/site([/a-zA-Z0-9]*).xoyo.com/images"/> 65 </localpath> 66 </plugin> 67 </head>
四、啓動sersync
[root@rsync_client ~]# /usr/local/sersync/sersync2 -d -r -o /usr/local/sersync/confxml.xml
[root@rsync_client ~]# ps -ef | grep -v "grep" | grep sersync
root 24590 1 0 19:46 ? 00:00:00 /usr/local/sersync/sersync2 -d -r -o /usr/local/sersync/confxml.xml測試
五、測試是否正常
在/tmp目錄下建立幾個文件看看目標端192.168.2.3(rsync server)是否已經收到ui
在/tmp目錄下刪除幾個文件看看目標端192.168.2.3(rsync server)是否也不存在url
以上二者知足說明部署成功!