centos 6.4 搭建rsync+sersync

sersync原理是使用rsync命令推送同步的文件到rsync客戶端 優點是同步快,實時同步 使用資源少 缺點是不只是雙向實時同步,也就是說客戶端新建文件不會同步到服務器端 對於要實施雙機實時同步的同學來說sersync不是一個好的辦法

150037801.png

sersync+rsync 客戶端IP爲192.168.16.130 服務器IP爲192.168.16.128

實現目標:服務器端(推送端)/data/同步到客戶端 /tmp/haha

客戶端(只有rsync)配置

yum -y install rsync


vi /etc/rsyncd.conf

uid=root

gid=root

max connections=36000

use chroot=no

log file=/var/log/rsyncd.log

pid file=/var/log/rsyncd.pid

lock file=/var/log/rsyncd.lock

[data]                     #rsync模塊名,後面配置sersync會用到

path=/tmp/haha             #該同步目錄只要uid所指定的用戶有寫權限即可

comment = website files

ignore errors = yes

read only = no

hosts allow = 192.168.16.0/24

#hosts deny = *

auth users = user

secrets file = /etc/rsync.pas


mkdir /tmp/haha

vi /etc/rsync.pas

user:123456

chmod 600 /etc/rsync.pas

rsync --daemon --config=/etc/rsyncd.conf

服務器端配置

yum -y install rsync

cd /usr/src

tar fzxv sersync.tar.gz

mkdir /usr/local/sersync

mkdir /usr/local/sersync/conf

mkdir /usr/local/sersync/bin

mkdir /usr/local/sersync/log

cd GNU-Linux-x86/

cp confxml.xml /usr/local/sersync/conf/

cp sersync2 /usr/local/sersync/bin/

cp /usr/src/GNU-Linux-x86/sersync2 /bin/

vi /etc/rsync.pas

123456

chmod 600 /etc/rsync.pas

cd /usr/local/sersync/conf/

vi confxml.xml

<?xml version="1.0" encoding="ISO-8859-1"?>

<head version="2.5">

   <host hostip="192.168.16.128" 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="true"/>

       <closeWrite start="true"/>

       <moveFrom start="true"/>

       <moveTo start="true"/>

       <attrib start="true"/>

       <modify start="true"/>

   </inotify>


   <sersync>

       <localpath watch="/data">                                         要修改的

           <remote ip="192.168.16.130" name="data"/>                      要修改的

           <!--<remote ip="192.168.8.39" name="tongbu"/>-->

           <!--<remote ip="192.168.8.40" name="tongbu"/>-->

       </localpath>

       <rsync>

           <commonParams params="-artuz"/>

           <auth start="true" users="user" passwordfile="/etc/rsync.pas"/>要修改的

           <userDefinedPort start="false" port="873"/><!-- 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="false" 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="/opt/tongbu">

           <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/p_w_picpaths"/>

       </localpath>

   </plugin>

</head>


killall sersync2 && sersync2 -r -d -o /usr/local/sersync/conf/confxml.xml


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