1.1 第一个里程碑:安装sersync软件

1.1.1 将软件上传到服务器当中并解压

1、上传软件到服务器上 rz -E

为了便于管理上传位置统一设置为 /server/tools 中

2、解压软件包

[root@backup sersync_installdir_64bit]# tree

.

└── sersync

├── bin

│   └── sersync

├── conf

│   └── confxml.xml

└── logs

1.1.2 二进制包安装方法

二进制包安装软件方法(绿色软件安装方法):

直接解压就可以使用

[root@nfs01 sersync_installdir_64bit]# mv sersync/ /usr/local/

[root@nfs01 tools]# tree /usr/local/sersync/

/usr/local/sersync/

├── bin

│   └── sersync

├── conf

│   └── confxml.xml

└── logs

3 directories, 2 files

1.2 第二个里程碑:编写sersync配置文件

1.2.1 常见的语法格式

rsync 配置文件编写:ini语法

sersync配置文件编写:xml语法

ansible配置文件编写:yml 语法

1.2.2 修改配置文件

编写前备份

[root@backup conf]# ll

total 4

-rw-r--r-- 1 root root 2214 Oct 26  2011 confxml.xml

[root@backup conf]# cp confxml.xml{,.bak}

6-11行表示排除同步的数据,等价于 --exclude 功能,表示排除

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-21行是利用inotify的功能监控指定的事件,等价与 -e create,delete…… 表示指定监控事件信息

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>

24-28行:推送到哪里 name=模块 是rsync服务器的地址

24         <localpath watch="/data"> #监控那个目录
 25             <remote ip="172.16.1.41" name="backup"/>
 26             <!--<remote ip="192.168.8.39" name="tongbu"/>-->
 27             <!--<remote ip="192.168.8.40" name="tongbu"/>-->
 28         </localpath>

29-35行 定义rsync推送时的参数信息。

注意:不要有单词拼写错误 (true),否则程序不能正常启动,卡死

29         <rsync>
 30             <commonParams params="-az"/>
 31             <auth start="true" users="rsync_backup" passwordfile="/etc/rsync.password"/>
 32             <userDefinedPort start="false" port="874"/><!-- port=874 -->
 33             <timeout start="false" time="100"/><!-- timeout=100 -->
 34             <ssh start="false"/>
 35         </rsync>

配置文件最终内容:

[root@nfs01 tools]# cat /usr/local/sersync/conf/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="/data">

<remote ip="172.16.1.41" name="nfsbackup"/>

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

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

</localpath>

<rsync>

<commonParams params="-az"/>

<auth start="true" users="rsync_backup" passwordfile="/etc/rsync.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="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/images"/>

</localpath>

</plugin>

</head>

1.3 第三里程碑: 启动sersync

1.3.1 修改文件的权限(可执行)

首先让程序让文件有执行权限

[root@nfs01 bin]# chmod a+x sersync

[root@nfs01 bin]# ll

total 1768

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

1.3.2 查看软件的帮助信息

[root@nfs01 bin]# ./sersync -h

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

_______________________________________________________

重要参数-d:启用守护进程模式

重要参数-r:在监控前,将监控目录与远程主机用rsync命令推送一遍

参数-n: 指定开启守护线程的数量,默认为10个

重要参数-o:指定配置文件,默认使用confxml.xml文件

参数-m:单独启用其他模块,使用 -m refreshCDN 开启刷新CDN模块

参数-m:单独启用其他模块,使用 -m socket 开启socket模块

参数-m:单独启用其他模块,使用 -m http 开启http模块

不加-m参数,则默认执行同步程序

________________________________________________________________

1.3.3 在程序的bin目录下启动程序

./sersync -dro /usr/local/sersync/conf/confxml.xml

1.3.4 启动方法二

将/usr/local/sersync/bin/程序的bin目录添加到PATH中

export PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin:/usr/local/sersync/bin/

然后sersync命令就能直接使用

[root@nfs01 scripts]# sersync -dro /usr/local/sersync/conf/confxml.xml

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/conf/confxml.xml

daemon thread num: 10

parse xml config file

host ip : localhost  host port: 8008

daemon start,sersync 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: 22 = 12(Thread pool nums) + 10(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 /data && rsync -az -R --delete ./ rsync_backup@172.16.1.41::nfsbackup --password-file=/etc/rsync.password >/dev/null 2>&1

run the sersync:

watch path is: /data

1.4 Inotify与 sersync总结对比

1.4.1 Inotify实时并发:

结论:经过测试,每秒200文件并发,数据同步几乎无延迟(小于1秒)

1.4.2 inotify 优点:

1)监控文件系统事件变化,通过同步工具实现实时数据同步。

1.4.3 inotify 缺点

1)并发如果大于200个文件(10-100k),同步就会有延迟

2)我们前面写的脚本,每次都是全部推送一次,但确实是增量的。也可以只同步变化的文件,不变化的不理。

3)监控到事件后,调用rsync同步是单进程的,而sersync为多进程同步。既然有了inotify-tools,为什么还要开发sersync?

1.4.4 serysync功能多:(inotify+rsync命令)

1)支持通过配置文件管理

2)真正的守护进程socket

3)可以对失败文件定时重传(定时任务功能)

4)第三方的HTTP接口(例如:更新cdn缓存)

5)默认多进程rsync同步

1.4.5 高并发数据实时同步方案小结:

1)inotify(sersync)+ rsync,是文件级别的。

2)drbd文件系统级别,文件系统级别,基于block块同步,缺点:备节点数据不可用

3)第三方软件的同步功能:mysql同步(主从复制),oracle,mongodb

4)程序双写,直接写两台服务器。

5)利用产品业务逻辑解决(读写分离,备份读不到,读主)

sersync实现数据实时同步的更多相关文章

  1. Linux下Rsync+sersync实现数据实时同步

    inotify 的同步备份机制有着缺点,于是看了sersync同步,弥补了rsync的缺点.以下转自:http://www.osyunwei.com/archives/7447.html 前言: 一. ...

  2. Rsync+sersync实现数据实时同步

    前言: 一.为什么要用Rsync+sersync架构? 1.sersync是基于Inotify开发的,类似于Inotify-tools的工具 2.sersync可以记录下被监听目录中发生变化的(包括增 ...

  3. CentOS7下Rsync+sersync实现数据实时同步

    近期公司要上线新项目,后台框架选型我选择当前较为流行的laravel,运行环境使用lnmp. 之前我这边项目tp32+apache,开发工具使用phpstorm. 新建/编辑文件通过phpstorm配 ...

  4. centos7服务搭建常用服务配置之二:Rsync+sersync实现数据实时同步

    目录 1.RSYNC数据备份 1.1 rsync服务简介 1.2 rsync特点和优势 1.3 rysnc运行模式简介 1.4 数据同步方式 2 Rsync实验测试 2.1 实验环境说明 2.2 服务 ...

  5. 项目实战:rsync+sersync实现数据实时同步

    一.组网介绍 本次实验使用两台主机: qll251 角色:Rsync server + Sersync server qll252 角色: Rsync client 本次实验采用CentOS7.7系统 ...

  6. CentOS7+rsync+sersync实现数据实时同步

    一.全网数据备份方案 1.需要备份的文件目录有(原则上,只要运维人员写入或更改的数据都需要备份)./data,/etc/rc.local,/var/spool/cron/root等,根据不同都服务器做 ...

  7. rsync+sersync实现文件实时同步

    前言: 一.为什么要用Rsync+sersync架构? 1.sersync是基于Inotify开发的,类似于Inotify-tools的工具 2.sersync可以记录下被监听目录中发生变化的(包括增 ...

  8. sersync基于rsync+inotify实现数据实时同步

    一.环境描述 需求:服务器A与服务器B为主备服务模式,需要保持文件一致性,现采用sersync基于rsync+inotify实现数据实时同步 主服务器A:192.168.1.23 从服务器B:192. ...

  9. (转)Linux系统sersync数据实时同步

    Linux系统sersync数据实时同步 原文:http://blog.csdn.net/mingongge/article/details/52985259 前面介绍了以守护进程的方式传输或同步数据 ...

随机推荐

  1. 第4章 同步控制 Synchronization ----事件(Event Objects)

    Win32 中最具弹性的同步机制就属 events 对象了.Event 对象是一种核心对象,它的唯一目的就是成为激发状态或未激发状态.这两种状态全由程序来控制,不会成为 Wait...() 函数的副作 ...

  2. web版的tty

      1.wetty Wetty是使用Node.js和websockets开发的一个开源`Web-based SSH` 2.环境配置 2.1.配置epel源 [epel] name=epel baseu ...

  3. 对python编程的初步理解

    一直以来零零散散有听过python,这周终于下定决心学python了.在网上了买个套视频教程,内容分周次学习,有详细的讲解.本人觉得非常好.这里谈谈一下第一周的学习的笔记.望路过的大神给予指正,不胜感 ...

  4. 对Java Web项目中路径的理解

    第一个:文件分隔符 坑比Window.window分隔符 用\;unix采用/.于是用File.separator来跨平台 请注意:这是文件路径.在File f = new File(“c:\\hah ...

  5. IDL 数组运算

    1.求大.求小和求余 IDL> arr=indgen(4) IDL> print,arr 0 1 2 3 IDL> print,arr>3 3 3 3 3 IDL> pr ...

  6. 有趣的flash例子

    仓鼠 <object type="application/x-shockwave-flash" data="http://cdn.abowman.com/widge ...

  7. Echarts数据可视化tooltip提示框,开发全解+完美注释

    全栈工程师开发手册 (作者:栾鹏) Echarts数据可视化开发代码注释全解 Echarts数据可视化开发参数配置全解 6大公共组件详解(点击进入): title详解. tooltip详解.toolb ...

  8. UWP 手绘视频创作工具技术分享系列 - 位图的绘制

    前面我们针对 SVG 的解析和绘制做了介绍,SVG 是图片的一种形式,而另一种很重要的图片是:位图,包括 png.jpeg.bmp 等格式.位图的基本规则是,组成的基本元素是像素点,由宽度 * 高度个 ...

  9. Java爬虫

    作为一位Java爬虫的初学者,分享一下自己的心得.所用到的jar包 org.codehaus.jettison.jar jsoup-1.7.3.jar个人认为爬虫的实现机制:获取Docume对象-&g ...

  10. This application failed to start because it could not find or load the Qt platform plugin "windows" 的问题原因以及解决方案

    1. 问题原因非常简单,经过各种百度,都没有找到解决方案,在此做一个记录备用. 2.原因就在于,项目目录使用了中文路径,然后出现了这个问题. 3.我是在使用 syncfusion 下的HTML 转PD ...