Linux下部署Sersync

1、 安裝rsync,安裝sersync前需要在兩個服務器上都安裝好rsync並daemon啓動。

  yum -y install rsync

2、 配置

  (1)服務端配置文件

  [root@server /root]#vim /etc/rsyncd.conf  (以下爲配置文件內容)

 

  uid = root

  gid = root

  use chroot = no

  max connections = 5

  pid file = /var/run/rsyncd.pid

  lock file = /var/run/rsync.lock

  log file = /var/log/rsyncd.log

  [http]

  path=/var/aa

  comment = backup

  ignore errors

  read only = no

  list = no

  auth users = root

  uid = root

  gid = root

  secrets file = /etc/rsyncd.secrets

  創建密碼文件並設置權限

  [root@server /root]#vim /etc/rsyncd.secrets (以下爲配置文件內容)

 

  root:123456

  [root@server /root]#vim /etc/rsyncd.password (以下爲配置文件內容)

 

  123456

 

  [root@server /root]#chmod 600 /etc/ rsyncd.secrets

  [root@server /root]#chmod 600 /etc/ rsyncd.password

  注意: rsyncd.secrets和rsyncd.password兩個文件必須chmod 600,否則會報錯。rsyncd.secrets是用於主動推送時,發送用的,rsyncd.password是用於接收到同步請求時驗收密碼用的。

  啓動

  [root@server /root]#rsync --daemon

  (2)客戶端

  配置需要同步的機器,即被推送接受同步文件的機器,這裏稱爲客戶機

  uid = root

  gid = root

  use chroot = no

  max connections = 5

  pid file = /var/run/rsyncd.pid

  lock file = /var/run/rsync.lock

  log file = /var/log/rsyncd.log

  [http]

  path=/var/aa

  comment = backup

  ignore errors

  read only = no

  list = no

  auth users = root

  uid = root

  gid = root

  secrets file = /etc/rsyncd.secrets

  創建密碼文件並設置權限

  [root@server /root]#vim /etc/rsyncd.secrets (以下爲配置文件內容)

 

  root:123456

  [root@server /root]#vim /etc/rsyncd.password (以下爲配置文件內容)

 

  123456

 

  [root@server /root]#chmod 600 /etc/ rsyncd.secrets

  [root@server /root]#chmod 600 /etc/ rsyncd.password

  注意: rsyncd.secrets和rsyncd.password兩個文件必須chmod 600,否則會報錯。rsyncd.secrets是用於主動推送時,發送用的,rsyncd.password是用於接收到同步請求時驗收密碼用的。

  啓動

  [root@server /root]#rsync --daemon

 

3、 安裝sersync

  wget -c http://sersync.googlecode.com/files/sersync2.5_64bit_binary_stable_final.tar.gz

  tar xf sersync2.5_64bit_binary_stable_final.tar.gz

  cd GNU-Linux-x86

  mkdir /usr/sersync2

  cp sersync2 /usr/

  cp confxml.xml /usr/sersync2

4、 配置sersync2

  vi /usr/sersync2/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="/var/aa/">

  <remote ip="10.1.43.201" name="http"/>

  </localpath>

  <rsync>

  <commonParams params="-artuz"/>

  <auth start="true" users="root" passwordfile="/etc/rsyncd/rsyncd.password"/>

  <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 execute once-->

  <crontab start="true" 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="/var/aa">

  <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>

  表明要將同步服務器上本地的/var/aa 路徑下的文件,同步到遠程服務器 10.1.43.201的http 模塊下。

  接下來,運行sersync2

  sersync2 -r -d -o /usr/sersync2/confxml.xml

  參數-r: 在開啓實時監控之前對同步服務器目錄與遠程目標機目錄進行一次整體同步。

  參數-o:指定配置文件,默認使用confxml.xml文件

  參數-d:啓用守護進程模式

 
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章