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:启用守护进程模式