一、实验环境

CentOS版本: 6.6(2.6.32.-504.el6.x86_64)

Rsync版本:  Rsync-3.0.6(系统自带)

Sersync版本:sersync2.5.4_64bit_binary_stable_final.tar.gz(下载上传)

二、准备工作

查看系统是否支持inotify及参数优化:

[root@backup ~]# ls -l  /proc/sys/fs/inotify/

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

总用量 0

0 dr-xr-xr-x 0 root root 0 12月 4 14:04 ..

0 dr-xr-xr-x 0 root root 0 12月 4 11:35 .

0 -rw-r--r-- 1 root root 0 12月 4 11:35 max_user_watches

0 -rw-r--r-- 1 root root 0 12月 4 11:35 max_user_instances

0 -rw-r--r-- 1 root root 0 12月 4 11:35 max_queued_events

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

返回以上内容,则系统支持inotify。这一步可能博友不太明白,本文实验是sersync实时同步,和支持inotify有什么关系。这是因为sersync实时监控时会调用 max_user_watches和 max_queued_events这两个文件

max_user_watches       #可实时监控的目录的最大个数,该值默认为8192

max_queued_events    #可实时监控的最大的队列事件, 超出这个值的事件将被丢弃。该值默认为16384

[root@backup ~]# cat /proc/sys/fs/inotify/*

16384

128

8192

[root@backup inotify]# echo 50000000 > max_user_watches

[root@backup inotify]# cat max_user_watches

50000000

[root@backup inotify]# echo 327679 > max_queued_events

[root@backup inotify]# cat max_queued_events

327679

关闭防火墙: service iptables stop                                               #(服务端,客户端)均关闭

chkconfig iptables off

关闭selinux:sed -i 's/SELINUX=disabled/SELINUX=enforcing/g' /etc/selinux/config #(服务端,客户端)均关闭

init 6 重启系统一定要!

三、Rsync服务端配置

[root@backup ~]# vi /etc/rsyncd.conf

#rsyncd.conf,create 2015-07-30,linuxzkq

uid = rsync

gid = rsync

use chroot = no

max connections = 200

timeout = 300

pid file = /var/run/rsyncd.pid

lock file = /var/run/rsync.lock

log file = /var/log/rsyncd.log

ignore errors

read only = false

list = false

hosts allow = 192.168.0.0/24

hosts deny = 0.0.0.0/32

auth users = rsync_backup           #此为虚拟用户

secrets file = /etc/rsync.password

[cc]

path = /cc/

保存退出!

[root@backup ~]# echo "rsync_backup:8700389">/etc/rsync.password #创建同步自动认证的用户名与密码

[root@backup ~]# cat /etc/rsync.password

rsync_backup:8700389

[root@backup ~]# chmod 600 /etc/rsync.password                   #处于安全考虑,赋予600权限

[root@backup ~]# ll /etc/rsync.password

-rw------- 1 root root 21 Jul 30 21:36 /etc/rsync.password

[root@backup ~]# mkdir /cc                                       #创建服务端同步目录

[root@backup ~]# useradd rsync -s /sbin/nologin

[root@backup ~]# chown -R rsync.rsync /cc

[root@backup ~]# rsync --daemon                                  #表示以守护进程的方式启动

[root@backup ~]# netstat -tunlp|grep 873

tcp        0      0 0.0.0.0:873                 0.0.0.0:*                   LISTEN      28631/rsync

tcp        0      0 :::873                      :::*                        LISTEN      28631/rsync

[root@backup ~]# ps -ef|grep rsync

root     28631     1  0 21:30 ?        00:00:00 rsync --daemon

root     28647 28596  0 21:32 pts/0    00:00:00 grep rsync

[root@backup ~]# echo "/usr/bin/rsync --daemon" >>/etc/rc.local  #加入开机自启动

[root@backup ~]# tail -1 /etc/rc.local

/usr/bin/rsync --daemon

四、Rsync客户端配置

[root@LAMP ~]# vi /etc/rsync.password

8700389

保存退出!

[root@LAMP ~]# cat /etc/rsync.password

8700389

[root@LAMP ~]# chmod 600 /etc/rsync.password

[root@LAMP ~]# ll /etc/rsync.password

-rw------- 1 root root 8 Jul 30 22:15 /etc/rsync.password

[root@LAMP ~]# mkdir /cc

[root@LAMP ~]# useradd rsync -s /sbin/nologin

[root@LAMP ~]# chown -R rsync.rsync /cc

[root@LAMP ~]# which rsync

/usr/bin/rsync

[root@LAMP ~]# rz -y

rz waiting to receive.

zmodem trl+C

100%    4686 KB 4686 KB/s 00:00:01       0 Errors.

[root@LAMP ~]# ll

-rw-r--r-- 1 root root  727290 Oct 26  2011 sersync2.5.4_64bit_binary_stable_final.tar.gz

[root@LAMP ~]# tar xf sersync2.5.4_64bit_binary_stable_final.tar.gz

[root@LAMP ~]# ll

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

[root@LAMP ~]# mv GNU-Linux-x86 /usr/local/sersync

[root@LAMP ~]# cd /usr/local/sersync

[root@LAMP ~]# ll

total 1772

-rwxr-xr-x 1 root root    2214 Oct 26  2011 confxml.xml

-rwxr-xr-x 1 root root 1810128 Oct 26  2011 sersync2

[root@LAMP ~]# cp confxml.xml confxml.xml-bak

[root@LAMP ~]# vi 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="/cc">

<remote ip="192.168.0.112" name="cc"/>

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

</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_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 /server/scripts/check_sersync.sh suffix-->

<filter start="false">

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

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

</filter>

</plugin>

<plugin name="socket">

<localpath watch="/cc">

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

"confxml.xml" 67L, 2267C written

:wq!  #保存退出

参数说明:

1)修改24-28行,定义同步的本地目录及远程目标服务器IP和模块名

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>

修改后内容为:

24         <localpath watch="/cc">

25             <remote ip="192.168.0.112" name="cc"/>

26         </localpath>

2) 修改29-35行,认证部分:

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>

修改后的内容:

32         <rsync>

33             <commonParams params="-artuz"/>

34             <auth start="true" users="rsync_backup" passwordfile="/e

tc/rsync.password"/>

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

-->

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

37             <ssh start="false"/>

38         </rsync>

3)修改36-37行,定义同步队列或事件失败后,再次同步失败队列或事件的时间间隔

36         <failLog path="/tmp/rsync_fail_log.sh" timeToExecute="60

"/><!--default every 60mins execute once-->

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

修改后的内容为:

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

40         <crontab start="true" schedule="600"><!--600mins-->

以上修改完了,配置sersync环境变量:

[root@LAMP ~]# echo "export PATH=$PATH:/usr/local/sersync/bin" >>/etc/profile

[root@LAMP ~]# tail -1 /etc/profile

export PATH=$PATH:/usr/local/sersync/bin

[root@LAMP ~]# source /etc/profile

[root@LAMP ~]# echo "/usr/local/sersync/sersync2 -d -r -o  /usr/local/sersync/confxml.xml" >>/etc/rc.local                        #加入开机自启动

[root@LAMP ~]# cat /etc/rc.local

#!/bin/sh

#

# This script will be executed *after* all the other init scripts.

# You can put your own initialization stuff in here if you don't

# want to do the full Sys V style init stuff.

touch /var/lock/subsys/local

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

[root@LAMP ~]# mkdir /server/scripts -p

[root@LAMP ~]# cd /server/scripts

[root@LAMP ~]# vi check_sersync.sh

#!/bin/sh

sersync="/usr/local/sersync/sersync2"

confxml="/usr/local/sersync/confxml.xml"

status=$(ps aux |grep 'sersync2'|grep -v 'grep'|wc -l)

if [ $status -eq 0 ];

then

$sersync -d -r -o $confxml &

else

exit 0;

fi

:wq!  #保存退出

[root@LAMP ~]# chmod +x check_sersync.sh

[root@LAMP ~]# ll

total 4

-rwxr-xr-x 1 root root 224 Aug  4 23:27 check_sersync.sh

[root@LAMP ~]# crontab -e  #加入定时任务

*/5 * * * * root /server/scripts/check_sersync.sh > /dev/null 2>&1  #每隔5分钟执行一次脚本

[root@LAMP ~]# sh check_sersync.sh

set the system param

execute:echo 50000000 > /proc/sys/fs/inotify/max_user_watches

execute:echo 327679 > /proc/sys/fs/inotify/max_queued_events

parse the command param

option: -d      run as a daemon

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

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

daemon thread num: 10

parse xml config file

host ip : localhost     host port: 8008

daemon start,sersync run behind the console

Start the crontab       Every 600 minutes rsync all the files to the remote servers entirely

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 /cc && rsync -artuz -R --delete ./ rsync_backup@192.168.0.110::cc --password-file=/etc/rsync.password >/dev/null 2>&1

run the sersync:

watch path is: /cc

[root@LAMP ~]# touch /cc/bb{1..500}.log

[root@LAMP ~]# ls

bb140.log  bb230.log  bb320.log  bb410.log  bb500.log

bb141.log  bb231.log  bb321.log  bb411.log  bb50.log

bb142.log  bb232.log  bb322.log  bb412.log  bb51.log

bb143.log  bb233.log  bb323.log  bb413.log  bb52.log

bb144.log  bb234.log  bb324.log  bb414.log  bb53.log

bb145.log  bb235.log  bb325.log  bb415.log  bb54.log

bb146.log  bb236.log  bb326.log  bb416.log  bb55.log

bb147.log  bb237.log  bb327.log  bb417.log  bb56.log

bb148.log  bb238.log  bb328.log  bb418.log  bb57.log

bb149.log  bb239.log  bb329.log  bb419.log  bb58.log

bb14.log   bb23.log   bb32.log   bb41.log   bb59.log

现在再到Rsync服务端查看/cc目录:

[root@backup ~]# ls /cc

bb140.log  bb230.log  bb320.log  bb410.log  bb500.log

bb141.log  bb231.log  bb321.log  bb411.log  bb50.log

bb142.log  bb232.log  bb322.log  bb412.log  bb51.log

bb143.log  bb233.log  bb323.log  bb413.log  bb52.log

bb144.log  bb234.log  bb324.log  bb414.log  bb53.log

bb145.log  bb235.log  bb325.log  bb415.log  bb54.log

bb146.log  bb236.log  bb326.log  bb416.log  bb55.log

bb147.log  bb237.log  bb327.log  bb417.log  bb56.log

bb148.log  bb238.log  bb328.log  bb418.log  bb57.log

bb149.log  bb239.log  bb329.log  bb419.log  bb58.log

bb14.log   bb23.log   bb32.log   bb41.log   bb59.log

以上测试都通过,说明inotify实时触发rsync同步脚本运行正常。

至此,Rsync+sersync实现数据实时同步完成,如有遗漏之处,还请广大博友拍砖指正!

Sersync实时同步企业应用配置实战的更多相关文章

  1. day04 sersync实时同步和ssh服务

    day04 sersync实时同步和ssh服务 sersync实时同步 1.什么是实时同步 实时同步是一种只要当前目录发生变化则会触发一个事件,事件触发后会将变化的目录同步至远程服务器. 2.为什么使 ...

  2. sersync 实时同步工具

    出处:http://code.google.com/p/sersync/ 当前版本的sersync依赖于rsync进行同步.如下图所示,在同步主服务器上开启sersync,将监控路径中的文件同步到目标 ...

  3. Rsync + sersync 实时同步备份

    一      Rsync + Sersync  实时同步介绍 1.Rsync 服务搭建介绍 云机上搭建Rsync server,在本地搭建Rsync Clinet. 2. Sersync 服务搭建介绍 ...

  4. sersync 实时同步

    1.什么是实时同步 ​ 监控一个目录的变化, 当该目录触发事件(创建\删除\修改) 就执行动作, 这个动作可以是 rsync同步 ,也可以是其他. 2.为什么要实时同步 1.能解决nfs单点故障问题. ...

  5. 5. Sersync实时同步

    rsync+Sersync数据的实时同步 sersync介绍 1.什么是实时同步 监控一个目录的变化, 当该目录触发事件(创建\删除\修改) 就执行动作, 这个动作可以是 rsync同步 ,也可以是其 ...

  6. 搭建WEB、NFS共享、sersync实时同步以及全网定时备份服务流程

    本次实验的主要目的: 1.搭建web服务,使用nfs服务共享的/data目录挂载到web站点目录上. 2.nfs服务器与backup服务器使用sersync实时同步/data目录中的文件. 3.bac ...

  7. sersync实时同步实战

    第1章 实时同步 1.1 什么是实时同步 实时同步是一种只要当前目录触发事件,就马上同步到远程的目录.rsync 1.2 为什么要实时同步web->nfs->backup 保证数据的连续性 ...

  8. 5、Sersync实时同步实战

    1.实时同步概述 1.什么是实时同步, 只要当前目录发生变化则会触发一个事件,事件触发后将变化的目录同步至远程服务器. 2.为什么要实时同步, 保证数据的连续性, 减少人力维护成本, 解决nfs单点故 ...

  9. sersync 实时同步文件

    sersync 主要用于服务器同步,web镜像等功能.sersync是使用c++编写,在结合rsync同步的时候,节省了运行时耗和网络资源.因此更快.sersync配置起来很简单.另外本项目相比较其他 ...

随机推荐

  1. android中设置快捷键方法setShortcut参数的说明

    setShortcut之所以要两个参数来设定两个快捷键是为了应对不同的手机键盘.数字快捷键为12键键盘(0~9,*,#,共12个按键)所准备的.其实我怀疑有这种键盘的手机能装Android么?因为我的 ...

  2. iOS-MVVM设计模式

    谈到MVVM不得不先说一下MVC,MVC(Model-View-Controller). Model模型:用来呈现数据. View视图:用来呈现用户界面. Controller控制器:用来调节模型与视 ...

  3. How to solve GM MDI cannot complete the installation

    Dear Joy, I have a problem using GM MDI diagnostic tool. When I installed it on my laptop, the tool ...

  4. 使用ueditor时候修改图片路径及其相关信息

    ueditor功能比较强大  使用也比较方便 但是有一些东西是需要我们自己根据实际情况去设置的 以下是关于图片/涂鸦/视频等上传信息的更改: 首先我们要找到配置文件config.json 注意不是co ...

  5. 介绍一些适用于 Web 开发者的 Atom 编辑器插件

    Atom 的社区很繁荣,有着丰富的扩展/插件(packages).安装 Atom 的 Package 非常简单,可以在编辑器的偏好设置里面安装,也可以在命令行中使用 apm 命令来安装. 在介绍适用于 ...

  6. Cookie的属性(cookie的设置、获取和删除)

    每个cookie都有四个可选的属性,他们分别控制cookie的生存周期.可见性.安全性等. Cookies最初设计时,是为了CGI编程.但是,我们也可以使用Javascript脚本来操纵cookies ...

  7. js原生bind()用法[注意不是jquery里面的bind()]

    <div id="a"> <div></div> <div></div> <div></div> ...

  8. 268条PCB Layout设计规范

    1 PCB布线与布局 PCB布线与布局隔离准则:强弱电流隔离.大小电压隔离,高低频率隔离.输入输出隔离.数字模拟隔离.输en入输出隔离,分界标准为相差一个数量级.隔离方法包括:空间远离.地线隔开. 2 ...

  9. poj 1182 食物链(关系并查集)

    食物链 Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 62824   Accepted: 18432 Description ...

  10. 电脑小白学习软件开发-C#语言基础之循环重点讲解,习题

    写代码也要读书,爱全栈,更爱生活.每日更新原创IT编程技术及日常实用视频. 我们的目标是:玩得转服务器Web开发,搞得懂移动端,电脑客户端更是不在话下. 本教程是基础教程,适合任何有志于学习软件开发的 ...