sersync服务实战

sersync服务实战

分别有机器:server-178/24client-b-179/24client-c-180/24

中心分发服务器Masterclient-c-180/24

备份服务器    :client-b-179/24server-178/24

第一步:首先在备份服务器端配置rsync的守护进程,然后在master端配置rsync的客户端 #这一步非常关键,如果在这里无法成功,后面的sersync服务也就无法成功。

第二步:在master端安装sersync服务程序,然后进行配置

 

需求:在中心分发服务器/www/web/www/http 这两个目录需要和两台备份服务器进行实时的同步,对应的目录是/data/www/web/data/www/http

 

方案1:分别对www下的子目录webhttp进行同步

方案2:对webhttp的上一级目录www进行同步

实战过程:

方案1:分别对www下的子目录webhttp进行同步

 

第一步:首先在备份服务器端配置rsync的守护进程,然后在master端配置rsync的客户端 

备份服务器如下:

client-b-179/24server-178/24执行以下相同的命令:

vi rsyncd.conf

echo "rsync_backup:123456">/etc/rsync.password

mkdir -p /www/web /www/http

server-178/24主机为例子:

[root@server etc]# mkdir -p /www/web /www/http

[root@server etc]# tree /www/

/www/

|-- http

`-- web

 

2 directories, 0 files

[root@server etc]# vi rsyncd.conf

添加以下内容:

#rsync_config__________start

#crated by crazy 20151030

#rsyncd.conf start##

uid = root

gid = root

use chroot = no

max connetctions = 200

timeout = 300

pid file = /var/run/rsyncd.pid

lock file = /var/run/rsync.lock

log file = /var/log/rsyhcd.log

igonre errors

read only = false

list = false

hosts allow = 192.168.1.0/24

hosts deny = 0.0.0.0/32

auth users = rsync_backup

secrets file = /etc/rsync.password

###########

[web]

comment = web by crazy 10-30

path = /www/web/

##########

[http]

comment = http by crazy 10-30

path = /www/http/

##########

#rsync_config__________end

继续执行以下操作

[root@server etc]# echo "rsync_backup:123456">/etc/rsync.password 

[root@server etc]# cat /etc/rsync.password

rsync_backup:123456

[root@server etc]# echo "#rsync daemon by crazy 20151031" >>/etc/rc.local

[root@server etc]# echo "/usr/bin/rsync --daemon" >>/etc/rc.local

中心分发服务器master配置如下:

[root@client-C /]# mkdir -p /www/web /www/http

[root@client-C /]# echo "123456">/etc/rsync.password 

[root@client-C /]# cat /etc/rsync.password 

123456

在中心分发服务器master手工测试是否成功:

touch /www/http/httpmaster.txt

touch /www/web/webmaster.txt

 rsync -avz -P /www/web [email protected]::web/ --password-file=/etc/rsync.password

     rsync -avz -P /www/http [email protected]::http/ --password-file=/etc/rsync.password 

 rsync -avz -P /www/web [email protected]::web/ --password-file=/etc/rsync.password

 rsync -avz -P /www/http [email protected]::http/ --password-file=/etc/rsync.password 

 

[root@client-C /]# touch /www/http/httpmaster.txt

[root@client-C /]# touch /www/web/webmaster.txt

[root@client-C /]# tree /www/

/www/

|-- http

|   `-- httpmaster.txt

`-- web

    `-- webmaster.txt

 

2 directories, 2 files

[root@client-C /]# rsync -avz -P /www/web [email protected]::web/ --password-file=/etc/rsync.password 

building file list ... 

2 files to consider

web/

web/webmaster.txt  #成功推送

           0 100%    0.00kB/s    0:00:00 (xfer#1, to-check=0/2)

 

sent 112 bytes  received 44 bytes  312.00 bytes/sec

total size is 0  speedup is 0.00

[root@client-C /]# rsync -avz -P /www/web [email protected]::web/ --password-file=/etc/rsync.password 

building file list ... 

2 files to consider

web/

web/webmaster.txt  #成功推送

           0 100%    0.00kB/s    0:00:00 (xfer#1, to-check=0/2)

 

sent 112 bytes  received 44 bytes  312.00 bytes/sec

total size is 0  speedup is 0.00

[root@client-C /]# rsync -avz -P /www/http [email protected]::http/ --password-file=/etc/rsync.password 

building file list ... 

2 files to consider

http/

http/httpmaster.txt  #成功推送

           0 100%    0.00kB/s    0:00:00 (xfer#1, to-check=0/2)

 

sent 114 bytes  received 44 bytes  105.33 bytes/sec

total size is 0  speedup is 0.00

[root@client-C /]# rsync -avz -P /www/http [email protected]::http/ --password-file=/etc/rsync.password 

building file list ... 

2 files to consider

http/

http/httpmaster.txt  #成功推送

           0 100%    0.00kB/s    0:00:00 (xfer#1, to-check=0/2)

 

sent 114 bytes  received 44 bytes  316.00 bytes/sec

total size is 0  speedup is 0.00

查看备份服务器前后情况:

server-178/24主机为例子:

[root@server etc]# tree /www/  #分发服务器推送前查看

/www/

|-- http  #分发服务器推送前

`-- web  #分发服务器推送前

 

2 directories, 0 files

[root@server etc]# tree /www/  #分发服务器推送后查看

/www/

|-- http

|   `-- http

|       `-- httpmaster.txt  #分发服务器推送过来的文件

`-- web

    `-- web

        `-- webmaster.txt  #分发服务器推送过来的文件

 

4 directories, 2 files

到此第一步的配置完成;

 

第二步:在master端安装sersync服务程序,然后进行配置

下载sersync:下载sersync2.5_32bit_binary_stable_final.tar.gz到真实windows电脑,使用secureCRTrz功能传送到master机器根目录下

[root@client-C /]# rz

rz waiting to receive.

 zmodem trl+C 

 

  100%     710 KB  710 KB/s 00:00:01       0 Errorsary_stable_final.tar.gz...

 

[root@client-C /]# mkdir /tools

[root@client-C /]# mv sersync2.5_32bit_binary_stable_final.tar.gz /tools/

[root@client-C /]# cd /tools/

[root@client-C tools]# ls

sersync2.5.4_64bit_binary_stable_final.tar.gz

[root@client-C tools]# tar -zxvf sersync2.5_32bit_binary_stable_final.tar.gz -C /usr/local/

GNU-Linux-x86/

GNU-Linux-x86/sersync2

GNU-Linux-x86/confxml.xml

[root@client-C tools]# cd /usr/local/

[root@client-C local]# ls

bin  games          include  libexec  share

etc  GNU-Linux-x86  lib      sbin     src

[root@client-C local]# ll

total 76

drwxr-xr-x 2 root root 4096 Aug  8  2008 bin

drwxr-xr-x 2 root root 4096 Aug  8  2008 etc

drwxr-xr-x 2 root root 4096 Aug  8  2008 games

drwxr-xr-x 2 root root 4096 Oct 26  2011 GNU-Linux-x86

drwxr-xr-x 2 root root 4096 Aug  8  2008 include

drwxr-xr-x 2 root root 4096 Aug  8  2008 lib

drwxr-xr-x 2 root root 4096 Aug  8  2008 libexec

drwxr-xr-x 2 root root 4096 Aug  8  2008 sbin

drwxr-xr-x 4 root root 4096 Oct 19 16:45 share

drwxr-xr-x 2 root root 4096 Aug  8  2008 src

[root@client-C local]# mv GNU-Linux-x86 sersync

[root@client-C local]# ll

total 76

drwxr-xr-x 2 root root 4096 Aug  8  2008 bin

drwxr-xr-x 2 root root 4096 Aug  8  2008 etc

drwxr-xr-x 2 root root 4096 Aug  8  2008 games

drwxr-xr-x 2 root root 4096 Aug  8  2008 include

drwxr-xr-x 2 root root 4096 Aug  8  2008 lib

drwxr-xr-x 2 root root 4096 Aug  8  2008 libexec

drwxr-xr-x 2 root root 4096 Aug  8  2008 sbin

drwxr-xr-x 2 root root 4096 Oct 26  2011 sersync

drwxr-xr-x 4 root root 4096 Oct 19 16:45 share

drwxr-xr-x 2 root root 4096 Aug  8  2008 src

[root@client-C local]# tree sersync/

sersync/

|-- confxml.xml

`-- sersync2

 

0 directories, 2 files

[root@client-C local]# cd sersync/

[root@client-C sersync]# mkdir conf bin logs  #创建目录,更加规范,显得专业

[root@client-C sersync]# ls

bin  conf  confxml.xml  logs  sersync2

[root@client-C sersync]# mv confxml.xml conf

[root@client-C sersync]# mv sersync2 bin/sersync

[root@client-C sersync]# ll

total 12

drwxr-xr-x 2 root root 4096 Oct 29 22:15 bin

drwxr-xr-x 2 root root 4096 Oct 29 22:14 conf

drwxr-xr-x 2 root root 4096 Oct 29 22:14 logs

[root@client-C sersync]# tree

.

|-- bin

|   `-- sersync

|-- conf

|   `-- confxml.xml

`-- logs

 

3 directories, 2 files

[root@client-C sersync]# cd conf/

[root@client-C conf]# cp confxml.xml confxml.xml.bak

[root@client-C conf]# vi confxml.xml

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

      2 <head version="2.5">

      3     <host hostip="localhost" port="8008"></host>

      4     <debug start="false"/>

      5     <fileSystem xfs="false"/>

      6     <filter start="false">

      7         <exclude expression="(.*)\.svn"></exclude>

      8         <exclude expression="(.*)\.gz"></exclude>

      9         <exclude expression="^info/*"></exclude>

     10         <exclude expression="^static/*"></exclude>

     11     </filter>

     12     <inotify>

     13         <delete start="true"/>

     14         <createFolder start="true"/>

     15         <createFile start="false"/>

     16         <closeWrite start="true"/>

     17         <moveFrom start="true"/>

     18         <moveTo start="true"/>

     19         <attrib start="false"/>

     20         <modify start="false"/>

     21     </inotify>

     22 

     23     <sersync>

     24         <localpath watch="/opt/tongbu">

     25             <remote ip="127.0.0.1" name="tongbu1"/>

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

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

     28         </localpath>

     29         <rsync>

     30             <commonParams params="-artuz"/>

     31             <auth start="false" users="root" passwordfile="/etc/rsync.pas"/>

     32             <userDefinedPort start="false" port="874"/><!-- port=874 -->

     33             <timeout start="false" time="100"/><!-- timeout=100 -->

     34             <ssh start="false"/>

     35         </rsync>

     36         <failLog path="/tmp/rsync_fail_log.sh" timeToExecute="60"/><!--default every 60mins execute once-->

     37         <crontab start="false" schedule="600"><!--600mins-->

     38             <crontabfilter start="false">

     39                 <exclude expression="*.php"></exclude>

     40                 <exclude expression="info/*"></exclude>

     41             </crontabfilter>

     42         </crontab>

     43         <plugin start="false" name="command"/>

     44     </sersync>

     45 

     46     <plugin name="command">

     47         <param prefix="/bin/sh" suffix="" ignoreError="true"/>          <!--prefix /opt/tongbu/mmm.sh suffix-->

     48         <filter start="false">

     49             <include expression="(.*)\.php"/>

     50             <include expression="(.*)\.sh"/>

     51         </filter>

     52     </plugin>

     53 

     54     <plugin name="socket">

     55         <localpath watch="/opt/tongbu">

     56             <deshost ip="192.168.138.20" port="8009"/>

     57         </localpath>

     58     </plugin>

     59     <plugin name="refreshCDN">

     60         <localpath watch="/data0/htdocs/cms.xoyo.com/site/">

     61             <cdninfo domainname="ccms.chinacache.com" port="80" username="xxxx" passwd="xxxx"/>

     62             <sendurl base="http://pic.xoyo.com/cms"/>

     63             <regexurl regex="false" match="cms.xoyo.com/site([/a-zA-Z0-9]*).xoyo.com/images"/>

     64         </localpath>

     65     </plugin>

     66 </head>

 

优化配置文件:

31行改成:<auth start="true" users="rsync_backup" passwordfile="/etc/rsync.password"/> 

33行改成:<timeout start="true" time="100"/><!-- timeout=100 -->

36行改成:

<failLog path="/usr/local/sersync/logs/rsync_fail_log.sh" timeToExecute="60"/><!--default every 60mins execute once-->

24-28行的内容替换成:

<!--web############################-->

<localpath watch="/www/web">

<remote ip="192.168.1.178" name="web"/>

<remote ip="192.168.1.179" name="web"/>

</localpath>

<!--http############################-->

<localpath watch="/www/http">

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

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

</localpath>

修改完成后的配置文件:

     [root@client-C conf]# cat -n confxml.xml

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

     2  <head version="2.5">

     3      <host hostip="localhost" port="8008"></host>

     4      <debug start="false"/>

     5      <fileSystem xfs="false"/>

     6      <filter start="false">

     7          <exclude expression="(.*)\.svn"></exclude>

     8          <exclude expression="(.*)\.gz"></exclude>

     9          <exclude expression="^info/*"></exclude>

    10          <exclude expression="^static/*"></exclude>

    11      </filter>

    12      <inotify>

    13          <delete start="true"/>

    14          <createFolder start="true"/>

    15          <createFile start="false"/>

    16          <closeWrite start="true"/>

    17          <moveFrom start="true"/>

    18          <moveTo start="true"/>

    19          <attrib start="false"/>

    20          <modify start="false"/>

    21      </inotify>

    22

    23      <sersync>

    24          </localpath>

    25          <!--web############################-->

    26          <localpath watch="/www/web">

    27                  <remote ip="192.168.1.178" name="web"/>

    28                  <remote ip="192.168.1.179" name="web"/>

    29          </localpath>

    30

    31          <!--http############################-->

    32          <localpath watch="/www/http">

    33                  <remote ip="192.168.1.178" name="http"/>

    34                  <remote ip="192.168.1.179" name="http"/>

    35          </localpath>

    36          <rsync>

    37              <commonParams params="-artuz"/>

    38              <auth start="true" users="rsync_backup" passwordfile="/etc/rsync.password"/>

    39              <userDefinedPort start="false" port="874"/><!-- port=874 -->

    40              <timeout start="true" time="100"/><!-- timeout=100 -->

    41              <ssh start="false"/>

    42          </rsync>

    43  <failLog path="/usr/local/sersync/logs/rsync_fail_log.sh" timeToExecute="60"/><!--default every 60mins execute once-->

    44          <crontab start="false" schedule="600"><!--600mins-->

    45              <crontabfilter start="false">

    46                  <exclude expression="*.php"></exclude>

    47                  <exclude expression="info/*"></exclude>

    48              </crontabfilter>

    49          </crontab>

    50          <plugin start="false" name="command"/>

    51      </sersync>

    52

    53      <plugin name="command">

    54          <param prefix="/bin/sh" suffix="" ignoreError="true"/>  <!--prefix /opt/tongbu/mmm.sh suffix-->

    55          <filter start="false">

    56              <include expression="(.*)\.php"/>

    57              <include expression="(.*)\.sh"/>

    58          </filter>

    59      </plugin>

    60

    61      <plugin name="socket">

    62          <localpath watch="/opt/tongbu">

    63              <deshost ip="192.168.138.20" port="8009"/>

    64          </localpath>

    65      </plugin>

    66      <plugin name="refreshCDN">

    67          <localpath watch="/data0/htdocs/cms.xoyo.com/site/">

    68              <cdninfo domainname="ccms.chinacache.com" port="80" username="xxxx" passwd="xxxx"/>

    69              <sendurl base="http://pic.xoyo.com/cms"/>

    70              <regexurl regex="false" match="cms.xoyo.com/site([/a-zA-Z0-9]*).xoyo.com/images"/>

    71          </localpath>

    72      </plugin>

    73  </head>

Sersync环境变量配置:

[root@client-C conf]# echo 'export PATH=$PATH:/usr/local/sersync/bin'>>/etc/profile

[root@client-C conf]# tail -1 /etc/profile

[root@client-C conf]# source /etc/profile

[root@client-C conf]# which sersync

/usr/local/sersync/bin/sersync

启动命令:

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

#一般来说-r参数仅在第一次同步的时候需要带上,第一次属于完全备份

[root@client-C conf]# sersync -r -d -o /usr/local/sersync/conf/confxml.xml

set the system param 

executeecho 50000000 > /proc/sys/fs/inotify/max_user_watches

executeecho 327679 > /proc/sys/fs/inotify/max_queued_events

parse the command param

option: -r      rsync all the local files to the remote servers before the sersync work

option: -d      run as a daemon

option: -o      config xml name:  /usr/local/sersync/conf/confxml.xml

daemon thread num: 10

parse xml config file

host ip : localhost     host port: 8008

daemon startsersync run behind the console 

use rsync password-file :

user is rsync_backup

passwordfile is         /etc/rsync.password

config xml parse success

please set /etc/rsyncd.conf max connections=0 Manually

sersync working thread 12  = 1(primary thread) + 1(fail retry thread) + 10(daemon sub threads) 

Max threads numbers is: 32 = 12(Thread pool nums) + 20(Sub threads)

please according your cpu use -n param to adjust the cpu rate

------------------------------------------

rsync the directory recursivly to the remote servers once

working please wait...

execute command: cd /www/web && rsync -artuz -R --delete ./  --timeout=100 [email protected]::web --password-file=/etc/rsync.password >/dev/null 2>&1 

run the sersync: 

watch path is: /www/web  #发现只有配置文件中第一个模块成功,下面测试证明

测试:

master上创建文件如下:

[root@client-C www]# touch /www/http/httpmaster.tt /www/web/webmaster.txt

[root@client-C www]# tree

.

|-- http

|   `-- httpmaster.tt

`-- web

    `-- webmaster.txt

 

2 directories, 2 files

 

 

查看备份服务器前后情况:

server-178/24主机为例子:

[root@client-B www]# tree /www/  #master创建文件前执行

/www/

|-- http

`-- web

 

2 directories, 0 files

[root@client-B www]# tree /www/  #master创建文件后执行

/www/

|-- http   #http的文件没有同步成功

`-- web

    `-- webmaster.txt  #只有一个同步成功

 

2 directories, 1 file

测试发现,单实例无法完成两个模块同时同步,只有web模块的文件可以备份成功,http的模块文件没有成功。

master端修改配置文件,启用两个实例修改如下:

[root@client-C conf]# cp confxml.xml confxml_http.xml  #复制

[root@client-C conf]# cp confxml.xml confxml_web.xml  #复制

[root@client-C conf]# vi confxml_http.xml   #把配置文件中web的模块删掉

        <localpath watch="/www/web">

            <remote ip="192.168.1.178" name="web"/>

            <remote ip="192.168.1.179" name="web"/>

        </localpath>

<?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="/www/http">     #http的配置文件中只保留http的模块

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

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

        </localpath>

        <rsync>

            <commonParams params="-artuz"/>

            <auth start="true"users="rsync_backup" passwordfile="/etc/rsync.password"/>

            <userDefinedPort start="false" port="874"/><!-- port=874 -->

            <timeout start="true" time="100"/><!-- timeout=100 -->

            <ssh start="false"/>

        </rsync>

        <failLog path="/usr/local/sersync/logs/rsync_http_fail_log.sh" timeToExecute="60"/><!--default every 60mins execute once-->

"confxml_http.xml" 66L, 2182C written

[root@client-C conf]# vi confxml_web.xml    #把配置文件中的http的模块删除

        <localpath watch="/www/http">

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

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

        </localpath>

<?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="/www/web">   #web的配置文件中只保留web的模块

            <remote ip="192.168.1.178" name="web"/>

            <remote ip="192.168.1.179" name="web"/>

        </localpath>

 

        <rsync>

            <commonParams params="-artuz"/>

            <auth start="true" users="rsync_backup" passwordfile="/etc/rsync.password"/>

            <userDefinedPort start="false" port="874"/><!-- port=874 -->

            <timeout start="true" time="100"/><!-- timeout=100 -->

            <ssh start="false"/>

        </rsync>

        <failLog path="/usr/local/sersync/logs/rsync_web_fail_log.sh" timeToExecute="60"/><!--default every 60mins execute once-->

        <crontab start="false" schedule="600"><!--600mins-->

            <crontabfilter start="false">

"confxml_web.xml" 66L, 2183C written

配置文件修改成功:

测试:

master端指定配置文件,启动两个实例如下

执行命令:

sersync -r -d -o /usr/local/sersync/conf/confxml_http.xml

sersync -r -d -o /usr/local/sersync/conf/confxml_web.xml 

ps -ef |grep sersync|grep -v grep

 

[root@client-C www]# tree  #查看监控的目录文件结构

.

|-- http

|   `-- httpmaster.txt

`-- web

    `-- webmaster.txt

 

2 directories, 2 files

[root@client-C www]# ps -ef |grep sersync

root      2819  2405  0 01:16 pts/0    00:00:00 grep sersync

[root@client-C www]# sersync -r -d -o /usr/local/sersync/conf/confxml

confxml_http.xml  confxml_web.xml   confxml.xml       confxml.xml.bak   confxml.xml.goog  

[root@client-C www]# sersync -r -d -o /usr/local/sersync/conf/confxml_http.xml 

set the system param

executeecho 50000000 > /proc/sys/fs/inotify/max_user_watches

executeecho 327679 > /proc/sys/fs/inotify/max_queued_events

parse the command param

option: -r      rsync all the local files to the remote servers before the sersync work

option: -d      run as a daemon

option: -o      config xml name:  /usr/local/sersync/conf/confxml_http.xml

daemon thread num: 10

parse xml config file

host ip : localhost     host port: 8008

daemon startsersync run behind the console 

use rsync password-file :

user is rsync_backup

passwordfile is         /etc/rsync.password

config xml parse success

please set /etc/rsyncd.conf max connections=0 Manually

sersync working thread 12  = 1(primary thread) + 1(fail retry thread) + 10(daemon sub threads) 

Max threads numbers is: 32 = 12(Thread pool nums) + 20(Sub threads)

please according your cpu use -n param to adjust the cpu rate

------------------------------------------

rsync the directory recursivly to the remote servers once

working please wait...

execute command: cd /www/http && rsync -artuz -R --delete ./  --timeout=100 [email protected]::http --password-file=/etc/rsync.password >/dev/null 2>&1 

run the sersync: 

watch path is: /www/http  #监控http目录,启动成功

[root@client-C www]# sersync -r -d -o /usr/local/sersync/conf/confxml_web.xml 

set the system param

executeecho 50000000 > /proc/sys/fs/inotify/max_user_watches

executeecho 327679 > /proc/sys/fs/inotify/max_queued_events

parse the command param

option: -r      rsync all the local files to the remote servers before the sersync work

option: -d      run as a daemon

option: -o      config xml name:  /usr/local/sersync/conf/confxml_web.xml

daemon thread num: 10

parse xml config file

host ip : localhost     host port: 8008

daemon startsersync run behind the console 

use rsync password-file :

user is rsync_backup

passwordfile is         /etc/rsync.password

config xml parse success

please set /etc/rsyncd.conf max connections=0 Manually

sersync working thread 12  = 1(primary thread) + 1(fail retry thread) + 10(daemon sub threads) 

Max threads numbers is: 32 = 12(Thread pool nums) + 20(Sub threads)

please according your cpu use -n param to adjust the cpu rate

------------------------------------------

rsync the directory recursivly to the remote servers once

working please wait...

execute command: cd /www/web && rsync -artuz -R --delete ./  --timeout=100 [email protected]::web --password-file=/etc/rsync.password >/dev/null 2>&1 

[root@client-C www]# run the sersync: 

watch path is: /www/web    #监控web目录,启动成功

[root@client-C www]# ps -ef |grep sersync|grep -v grep

root      2823     1  0 01:17 ?        00:00:00 sersync -r -d -o /usr/local/sersync/conf/confxml_http.xml

root      2843     1  0 01:17 ?        00:00:00 sersync -r -d -o /usr/local/sersync/conf/confxml_web.xml

 

 

查看备份服务器前后情况:

server-178/24主机为例子:

[root@server www]# tree /www/   #master启动实例前执行

/www/

|-- http

`-- web

 

2 directories, 0 files

[root@client-B www]# tree /www/  #master启动实例后执行

 

/www/

|-- http

|   `-- httpmaster.txt  #同步过来了

`-- web

    `-- webmaster.txt   #同步过来了

 

2 directories, 2 files

方案1:分别对www下的子目录webhttp进行同步,配置完成;

方案2:对web和http的上一级目录www进行同步

Master端的修改如下:

[root@client-C conf]# cp confxml.xml confxml_www.xml

[root@client-C conf]# vi confxml_www.xml 

[root@client-C conf]# cat -n confxml_www.xml 

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

     2  <head version="2.5">

     3      <host hostip="localhost" port="8008"></host>

     4      <debug start="false"/>

     5      <fileSystem xfs="false"/>

     6      <filter start="false">

     7          <exclude expression="(.*)\.svn"></exclude>

     8          <exclude expression="(.*)\.gz"></exclude>

     9          <exclude expression="^info/*"></exclude>

    10          <exclude expression="^static/*"></exclude>

    11      </filter>

    12      <inotify>

    13          <delete start="true"/>

    14          <createFolder start="true"/>

    15          <createFile start="false"/>

    16          <closeWrite start="true"/>

    17          <moveFrom start="true"/>

    18          <moveTo start="true"/>

    19          <attrib start="false"/>

    20          <modify start="false"/>

    21      </inotify>

    22

    23      <sersync>

    24          <localpath watch="/www">    #修改后

    25              <remote ip="192.168.1.178" name="www"/>  #修改后   

    26              <remote ip="192.168.1.179" name="www"/>  #修改后   

    27          </localpath>

    28

    29          <rsync>

    30              <commonParams params="-artuz"/>

    31              <auth start="true" users="rsync_backup" passwordfile="/etc/rsync.password"/>

    32              <userDefinedPort start="false" port="874"/><!-- port=874 -->

    33              <timeout start="true" time="100"/><!-- timeout=100 -->

    34              <ssh start="false"/>

    35          </rsync>                                               

    36          <failLog path="/usr/local/sersync/logs/rsync_fail_log.sh" timeToExecute="60"/><!--default every 60mins execute once-->

    37          <crontab start="false" schedule="600"><!--600mins-->

    38              <crontabfilter start="false">

    39                  <exclude expression="*.php"></exclude>

    40                  <exclude expression="info/*"></exclude>

    41              </crontabfilter>

    42          </crontab>

    43          <plugin start="false" name="command"/>

    44      </sersync>

    45

    46      <plugin name="command">

    47          <param prefix="/bin/sh" suffix="" ignoreError="true"/>  <!--prefix /opt/tongbu/mmm.sh suffix-->

    48          <filter start="false">

    49              <include expression="(.*)\.php"/>

    50              <include expression="(.*)\.sh"/>

    51          </filter>

    52      </plugin>

    53

    54      <plugin name="socket">

    55          <localpath watch="/opt/tongbu">

    56              <deshost ip="192.168.138.20" port="8009"/>

    57          </localpath>

    58      </plugin>

    59      <plugin name="refreshCDN">

    60          <localpath watch="/data0/htdocs/cms.xoyo.com/site/">

    61              <cdninfo domainname="ccms.chinacache.com" port="80" username="xxxx" passwd="xxxx"/>

    62              <sendurl base="http://pic.xoyo.com/cms"/>

    63              <regexurl regex="false" match="cms.xoyo.com/site([/a-zA-Z0-9]*).xoyo.com/images"/>

    64          </localpath>

    65      </plugin>

    66  </head>

[root@client-C conf]# cd  /www/

[root@client-C www]# tree

.

|-- http

|   `-- httpmaster.txt

`-- web

    `-- webmaster.txt

 

2 directories, 2 files

[root@client-C www]# touch /www/http/httpmaster.log /www/web/webmaster.log

[root@client-C www]# tree

.

|-- http

|   |-- httpmaster.log

|   `-- httpmaster.txt

`-- web

    |-- webmaster.log

    `-- webmaster.txt

 

2 directories, 4 files

[root@client-C www]# pkill sersync

[root@client-C www]# ps -ef |grep sersync|grep -v grep

[root@client-C www]# sersync -r -d -o /usr/local/sersync/conf/confxml_www.xml 

set the system param

executeecho 50000000 > /proc/sys/fs/inotify/max_user_watches

executeecho 327679 > /proc/sys/fs/inotify/max_queued_events

parse the command param

option: -r      rsync all the local files to the remote servers before the sersync work

option: -d      run as a daemon

option: -o      config xml name:  /usr/local/sersync/conf/confxml_www.xml

daemon thread num: 10

parse xml config file

host ip : localhost     host port: 8008

daemon startsersync run behind the console 

use rsync password-file :

user is rsync_backup

passwordfile is         /etc/rsync.password

config xml parse success

please set /etc/rsyncd.conf max connections=0 Manually

sersync working thread 12  = 1(primary thread) + 1(fail retry thread) + 10(daemon sub threads) 

Max threads numbers is: 32 = 12(Thread pool nums) + 20(Sub threads)

please according your cpu use -n param to adjust the cpu rate

------------------------------------------

rsync the directory recursivly to the remote servers once

working please wait...

execute command: cd /www && rsync -artuz -R --delete ./  --timeout=100 [email protected]::www --password-file=/etc/rsync.password >/dev/null 2>&1 

run the sersync: 

watch path is: /www

[root@client-C www]# ps -ef |grep sersync|grep -v grep

root      2906     1  0 02:09 ?        00:00:00 sersync -r -d -o /usr/local/sersync/conf/confxml_www.xml

备份服务器配置修改如下:

server-178/24主机为例子:

[root@server www]# cat /etc/rsyncd.conf

#rsync_config__________start

#crated by crazy 2006-6-5

#rsyncd.conf start##

uid = root

gid = root

use chroot = no

max connetctions = 200

timeout = 300

pid file = /var/run/rsyncd.pid

lock file = /var/run/rsync.lock

log file = /var/log/rsyhcd.log

igonre errors

read only = false

list = false

hosts allow = 192.168.1.0/24

hosts deny = 0.0.0.0/32

auth users = rsync_backup

secrets file = /etc/rsync.password

###########

[www]       #只保留www的模块

comment = www by crazy 10-30

path = /www/   #监控的目录

##########

#rsync_config__________end

查看备份服务器前后情况:

server-178/24主机为例子:

[root@server www]# rm -rf *   

[root@server www]# tree   #master启动实例前查看

.

 

0 directories, 0 files

[root@server www]# tree /www/  #master启动实例后查看

/www/

|-- http    #成功推送

|   |-- httpmaster.log   #成功推送

|   `-- httpmaster.txt    #成功推送

`-- web    #成功推送

    |-- webmaster.log    #成功推送

    `-- webmaster.txt     #成功推送

 

2 directories, 4 files

方案2:对webhttp的上一级目录www进行同步,配置完成;

 

总结:

sersync 需要同步多个目录,需要使用 “-O”参数指定配置文件,实现开启多个实例

在第一次同步的时候,使用  -r 参数属于完全的同步。


你可能感兴趣的:(服务器,master,客户端,程序,守护)