sersync2.5+rsync实现数据同步

一、安装

(1)目标服务器

$ tar -zxvf rsync-3.0.9.tar.gz
$ cd rsync-3.0.9
$ ./configure --prefix=/opt/rsync
$ make && make install
  
$ cd /opt/rsync/
$ mkdir etc
$ vim /etc/rsyncd.conf
uid=nobody
gid=nobody
use chroot=no
max connections=200
log file=/var/log/rsyncd.log
pid file=/var/run/rsyncd.pid
lock file=/var/run/rsyncd.lock
  
[http]
uid=root
gid=root
path=/opt/nginx/html/sync
comment = wwwroot
read only = no
write only = no
list = yes
ignore errors = yes
hosts allow = 192.168.1.51/24
hosts deny = *

注 :“[http] ”下面会用到

$ /opt/rsync/bin/rsync --daemon --config=/etc/rsyncd.conf
$ iptables -A INPUT -p tcp --dport 873 -j ACCEPT

(2)源服务器

$ tar -zxvf sersync2.5.4_64bit_binary_stable_final.tar.gz
$ mv GNU-Linux-x86/ /opt/sersync2.5
$ cd /opt/sersync2.5/
$ vim /opt/sersync2.5/confxml.xml
<?xml version="1.0" encoding="ISO-8859-1"?>
<head version="2.5">
    <host hostip="192.168.1.51" 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="/opt/nginx/html/sync">
            <remote ip="192.168.1.52" name="http"/>
  
        <failLog path="/var/log/sersync2.log" timeToExecute="60"/>
......

注:可更改localpath下watch的站点目录,remote中的name即为上一步注意中的[http]。


(3)配置完成,先做一次整体同步

$ /opt/sersync2.5/sersync2 -r -o /opt/sersync2.5/confxml.xml

(4)守护进程模式启动sersync2

$ /opt/sersync2.5/sersync2 -d -o /opt/sersync2.5/confxml.xml


二、新增同步的站点


(1)更改“源代码服务器”上的rsyncd.conf

vim /etc/rsyncd.conf

增加:

[www.xuejiehome.com]
path=/web/www.xuejiehome.com
comment = www.xuejiehome.com
ignore errors = yes
read only = no

(2)将上面的文件同步至“目标服务器”

scp /etc/rsyncd.conf root@slave:/etc/rsyncd.conf

(3)重启目标服务器上的rsync

rsync --daemon

(4)在“源代码服务器”上新建要同步的站点配置文件

vim /opt/sersync2/sites/www.xuejiehome.com.conf
<?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="/web/www.xuejiehome.com">
        <remote ip="ali-web1" name="www.xuejiehome.com"/>
        <remote ip="ali-web2" name="www.xuejiehome.com"/>
        <remote ip="ali-web3" name="www.xuejiehomecom"/>
        <remote ip="ali-web4" name="www.xuejiehome.com"/>
    </localpath>
    <rsync>
        <commonParams params="-artuz"/>
        <auth start="false" users="root" passwordfile="/etc/rsync.pas"/>
        <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="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>
</head>

(5)启动同步服务

/opt/sersync2/sersync2 -o /opt/sersync2/sites/www.xuejiehome.com.conf -r -d


注意:

   1. 被同步的服务器上要先创建好被同步的文件夹/web/www.xuejiehome.com


by 雪洁 2015-07-31 08:53:06 1718 views
我来说几句

相关文章