通过 rsync sersync 实现高效的数据实时同步架构

3 篇文章 0 订阅

企业级案例:通过 rsync sersync 实现高效的数据实时同步架构

Sersync的介绍

sersync主要用于服务器同步,web镜像等功能。基于boost1.43.0,inotify api,rsync command.开发。目前使用的比较多的同步解决方案是inotify-tools+rsync ,另外一个是google开源项目Openduckbill(依赖于inotify- tools),这两个都是基于脚本语言编写的。相比较上面两个项目,本项目优点是:

  1. Sersync 使用 c++ 编写,对 linux 系统文件产生的临时文件和重复的文件操作会进行过滤,在本文后面会提到该点。使用 rsync sersyc结合做同步的时候,会大大减少运行时所消耗的本地以及网络资源,因此在速度方面有显著提升。
  2. 相比 Inotify-tools 和 Openduckbill,Sersync 配置起来更为简单方便。在谷歌 Sersync 项目下载的安装包的 bin 目录下,放置了已经编译好的二进制文件,搭配 bin 目录下的xml文件可以直接部署使用。
  3. Sersync 采用多线程(默认10)进行同步(即可以并发同步多个不同文件),尤其是针对较大文件同步的时候,它能够保证多个服务器实时保持同步状态。
  4. Sersync 自带了出错处理机制。它可以通过失败队列自动对之前出错的文件进行重新同步操作。如果届时依旧失败,它会每 10 个小时对同步失败的文件再进行重新同步操作,直到文件同步为止。
  5. Sersync 自带有 crontab 功能,因此不需要借助系统的 crontab ,只需在 xml 配置文件中开启该功能,即可按预先的配置,每隔一段时间自动做一次整体同步操作。
  6. Sersync 还自带了 socket 与 refreshCDN 的协议扩展,可以满足有特殊需求的公司二次开发。(之前的版本有https扩展,目前已去除)

https://static.cnhzz.com/wp-content/uploads/2014/08/rsync_sersync.png

针对上图的设计架构,这里做几点说明,来帮助大家阅读和理解该图:

  1. 线程组线程是等待线程队列的守护线程,当事件队列中有事件产生的时候,线程组守护线程就会逐个唤醒同步线程。当队列中 Inotify 事件较多的时候,同步线程就会被全部唤醒一起工作。这样设计的目的是为了能够同时处理多个 Inotify 事件,从而提升服务器的并发同步能力。同步线程的最佳数量=核数 x 2 + 2。
  2. 那么之所以称之为线程组线程,是因为每个线程在工作的时候,会根据服务器上新写入文件的数量去建立子线程,子线程可以保证所有的文件与各个服务器同时同步。当要同步的文件较大的时候,这样的设计可以保证每个远程服务器都可以同时获得需要同步的文件。
  3. 服务线程的作用有三个:
    • 处理同步失败的文件,将这些文件再次同步,对于再次同步失败的文件会生成 rsync_fail_log.sh 脚本,记录失败的事件。
    • 每隔10个小时执行 rsync_fail_log.sh 脚本一次,同时清空脚本。
    • crontab功能,可以每隔一定时间,将所有路径整体同步一次。
  4. 过滤队列的建立是为了过滤短时间内产生的重复的inotify信息,例如在删除文件夹的时候,inotify就会同时产生删除文件夹里的文件与删除文件夹的事件,通过过滤队列,当删除文件夹事件产生的时候,会将之前加入队列的删除文件的事件全部过滤掉,这样只产生一条删除文件夹的事件,从而减轻了同步的负担。同时对于修改文件的操作的时候,会产生临时文件的重复操作。

Ifnotify事件分析

下面来用具体数据去做分析,来解释为什么 Sersync 比 Inotify-tools 和 Openduckbill 更优秀!
首先来看一张图,这张图是从谷歌 Sersync 项目组的分析文档里面摘出来的,该图是对同一个文件做write and close操作的时候,产生的10个事件。

wq

为什么我们认为脚本监控效率低?

由于我们执行复制,移动,新建,删除等操作时,会产生诸多事件。又上图来看他除了产生.开头的隐藏临时文件和~结尾的临时文件,还产生了3个4913的数字命名的临时文件(注意,在 write 文件的时候,总会产生这3个数字文件,除非write的文件名叫做4913时,才会产生别的数字命名的事件)。

因此当我们使用脚本监控,即使通过使用 --exclude 这样的选项结合正则语法,也无法完美过滤掉一些文件系统产生的临时文件和临时事件,这样就造成了 rsync 的反复执行。即便你把“.”开头与“~”结尾的事件过滤了,对于test文件仍旧有3次操作,分别是8、64和256。

补充:这里简单介绍下事件名称与对应代码。

事件256代表create事件,
事件8代表write_close事件,
事件512代表remove事件,
事件64move_from事件,即将文件mv出当前路径时产生事件。
事件128move_to事件,即将其它路径的文件移入到当前路径。

移出与移入操作可以通过cookie值来确定是否是同一文件。

由此可见,当移动操作时候,是将 test 移动为 test~ ,其实是修改了名字,通过 cookie 可以看出,它们是对同一文件的操作。

此时,我们 Sersync 的过滤队列效果就出来了!以下是过滤队列的三大作用!

1、过滤队列的第一个作用

按照如上的情形,如果通过过滤队列,就只会剩下一个 8 号事件,一定程度上也提高了同步的效率。

2、过滤队列的第二个作用

当你在本机删除目录的时候,假设你删除了一个包含 5 个文件的目录。Inotify 会产生 6 个事件出来,分别是 5 个文件删除事件和 1 个目录删除事件。如果使用过滤队列的话,正常情况下会只产生一个目录删除事件,这无疑大大减少了 Inotify 事件的产生,从而减少 Rsync 无谓的同步次数。当然,这里说的也不绝对。如果这 6 个事件分多次读到进入队列,那么可能还没来得及过滤,就已经被同步线程从队列中取走同步了,但是这确实在一定程度上减少了删除目录时的同步通信次数。

3、过滤队列的第三个作用

它可以过滤监控目录下的目录。如果我们不想同步目录下的某些目录或者一些后缀的文件,只需要在inotify启动的时候,remove 掉那些不需监控的子目录监控即可。对于不需要监控的子目录,产生的文件事件就会从载入同步队列前过滤掉。如果使用 Rsync 用 -exclude 参数虽然也可以实现过滤,但是还要与 Rsync 守护进程进行了一次交互才行。

下面是一些关于 Inotfy识别事件和 Sersync 的资料博文,大家可以去看一看:

https://code.google.com/p/sersync
https://www.ibm.com/developerworks/cn/linux/l-inotifynew/
https://hi.baidu.com/johntech/item/282552cfe6edb735449416e3

实验环境

内核版本:2.6.32-431.el6.x86_64
操作系统:centos系统采用最小化安装,系统经过了基本优化,selinux为关闭状态,iptables为无限制模式
源码包存放位置:/usr/local/src
客户端(Rsync+Sersync):这里实际生产环境下应该一个主master-rsync-sersync和一个备slave-rsync-sersync,防止单点故障
如果一个客户端宕机,备客户端会自动接管业务,采用ha-drbd架构(本实验暂时不做)
主机名:master-rsync-sersync    IP172.16.0.2
主机名:slave-rsync-sersyn  IP172.16.0.3
服务端(web1业务+rsync):IP172.16.0.4,主机名:rsync-web-server-1
服务端(web2业务+rsync):IP172.16.0.5,主机名:rsync-web-server-2
服务端(web3业务+rsync):IP172.16.0.6,主机名:rsync-web-server-3
rsync版本:https://rsync.samba.org/ftp/rsync/rsync-3.1.1.tar.gz
sersync版本:https://sersync.googlecode.com/files/sersync2.5.4_64bit_binary_stable_final.tar.gz

企业级 rsync sersync 架构图

rsync_sersync

第一步:在服务端部署上rsync(3个rsync-web-server都需要操作这一步)
#最小化安装的centos6.X可能需要安装一些基础的库,不装会编译通过不了提示各种错误。
yum install gcc perl
#下载源码包,解压缩,编译安装
wget https://rsync.samba.org/ftp/rsync/rsync-3.1.1.tar.gz
tar zxvf rsync-3.1.1.tar.gz
cd cd rsync-3.1.1
./configure.sh
make && make install
第二步:在服务端上创建一个rsync配置文件(默认没有)
cat > /etc/rsyncd.conf < < EOF
#Rsync server
#created by bingoku 15:01 2014.8.19
##rsyncd.conf start##
#uid gid 表示对后面模块中的path路径拥有什么样的权限
uid = root
gid = root
#如果"use chroot"指定为true,那么rsync在传输文件以前首先chroot到path参数所指定的目录下。这样做的原因是实现额外的安全防护,但是缺 点是需要以roots权限,并且不能备份指向外部的符号连接所指向的目录文件。默认情况下chroot值为true。
use chroot = no
# 定义连接数2000
max connections = 2000
# 600秒超时
timeout = 600
pid file = /var/run/rsyncd.pid
lock file = /var/run/rsync.lock
log file = /var/log/rsyncd.log
# 忽略错误
ignore errors
# false才能上传文件,true不能上传文件
read only = false
list = false
hosts allow = 172.16.0.2/24
hosts deny = 0.0.0.0/32
# 虚拟用户,同步时需要用这个用户
auth users = rsync_backup
# 密码文件 格式(虚拟用户名:密码)
secrets file = /etc/rsync.password
#####################################
# 模块名称
[www]
# comment注释
comment = www by bingoku 14:18 2014.8.19
##path指 模块的路径必须填写,且真实存在
path = /data0/www/www/
#####################################
[bbs]
comment = bbs by bingoku 14:18 2014.8.19
path = /data0/www/bbs/
#####################################
[blog]
comment = blog by bingoku 14:18 2014.8.19
path = /data0/www/blog/
#####################################
EOF

说明:

  • 这是一份带有注释的配置文件。是一个多目录同步案例。可以根据自己的需求,选择,如果只同步一个目录,那就只需写一个同步模块和目录。
  • 特别注意hosts allow和hosts deny的设定,可以做好基本的安全设置。
  • 业务需求对被同步目录要有写入和更新的权限,因此uid和gid都用了root权限。
第三步:在服务端,创建接收同步(推送过来)的目录(必须跟配置文件中的模块指定的路径一致!)
mkdir /data0/www/{www,bbs,blog} -p

说明:

  • 实际生产环境下,可能已经有了准备等待同步的目录,无须创建,修改模块路径就可以了。
  • 需要在服务端都有对应的目录才可以。因此都需要执行此次创建目录,否则rsync会因为path路径问题无法启动。
第四步:在服务端上配置相关认证和权限。
#创建password密码文件且写入 虚拟用户名和密码
echo 'rsync_backup:redhat' > /etc/rsync.password
#修改密码文件赋予权限(必须操作)
chmod 600 /etc/rsync.password

说明:rsync.password 文件的权限必须修改。不然同步不了。

第五步:以守护进程的方式启动rsync服务
#默认安装路径下的rsync
/usr/local/bin/rsync --daemon
#验证是否启动成功
[root@c6mini ~]# lsof -i tcp:873
COMMAND  PID USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
rsync   1051 root    3u  IPv4   8625      0t0  TCP *:rsync (LISTEN)
rsync   1051 root    5u  IPv6   8626      0t0  TCP *:rsync (LISTEN)

说明:

  • lsof命令一般都没有安装,需要yum install lsof 这个命令可以通过端口反查进程名称。

第六步:在服务端上面把rsync添加到开机自启动

#按标准添加一条注释,方便以后维护
echo "# rsyncd service daemon by bingoku 20140819" >>/etc/rc.local
echo "/usr/local/bin/rsync --daemon" >> /etc/rc.local
#验证下是否添加
[root@c6mini ~]# grep daemon /etc/rc.local
# rsyncd service daemon by bingoku 20140819
/usr/local/bin/rsync --daemon

说明:rsync的重启,没有命令和脚本,因此需要结束后台守护进程,然后再启动的方式重启。

#结束进程
pkill rsync
#再次启动
/usr/local/bin/rsync --daemon

特别说明:上面操作的这六个步骤都需要在,你的服务端上面执行。


在客户端上部署rsync和sersync

第一步:在客户端上安装和配置rsync的认证权限。
yum install gcc perl
cd /usr/local/src
wget https://rsync.samba.org/ftp/rsync/rsync-3.1.1.tar.gz
tar zxvf rsync-3.1.1.tar.gz
cd cd rsync-3.1.1
./configure.sh
make && make install
第二步:在客户端上,仅配置password文件且,只写入和服务端对应的密码
#仅写入和服务端虚拟用户对应的密码
echo "redhat" > /etc/rsync.password
#修改密码文件的权限(必须)
chmod 600 /etc/rsync.password
第三步:创建准备同步(推送)给服务端的目录和一些测试文件
#创建目录
mkdir /data0/www/{www,bbs,blog} -p
#创建测试文件
touch /data0/www/{www/index.html,bbs/a.jpg,blog/prr.jpg}
第四步:执行同步目录(主要是测试下推送到服务端的是否正常)
rsync -avzP /data0/www/www rsync_backup@172.16.0.4::www/ --password-file=/etc/rsync.password
rsync -avzP /data0/www/bbs rsync_backup@172.16.0.4::bbs/ --password-file=/etc/rsync.password
rsync -avzP /data0/www/blog rsync_backup@172.16.0.4::blog/ --password-file=/etc/rsync.password

说明:这里,仅记录了一个 向服务端推送的内容的命令,测试其它服务端改下主机IP就可以。同步完毕后进入服务端的相应目录查看下,文件是否存在。
确保这一步,是没人和错误提示的。

第五步:安装和规范sersync目录结构

#获取安装包:https://code.google.com/p/sersync/downloads/list
cd /usr/local/src
wget https://sersync.googlecode.com/files/sersync2.5.4_64bit_binary_stable_final.tar.gz
tar zxvf sersync2.5.4_64bit_binary_stable_final.tar.gz
cp -r GNU-Linux-x86 /usr/local/sersync
cd /usr/local/sersync/
#按标准规范sersync目录结构方便日后管理。
mkdir conf bin logs
mv confxml.xml conf
mv sersync2 bin/sersync

第六步:配置sersync

#备份一份默认的conxml.xml作为备份
cp conf/confxml.xml conf/confxml.xml.bak.$(date +%F)
#mv一个conxml.xml为 conxml_www.xml
cd conf
mv confxml.xml confxml_www.xml
#修改conxml_www.xml配置文件 达到能同步且高效的作用.
#
#
#
#修改24-28行的内容,原内容为:
#
#定义本地要同步的目录
<localpathwatch ="/opt/tongbu">
        #同步到哪个机器,,同步到机器的哪个模块
        <remoteip ="127.0.0.1" name="tongbu1"></remoteip>
        <!--<remoteip="192.168.8.39" name="tongbu"/>-->
        <!--<remoteip="192.168.8.40" name="tongbu"/>-->

#
#修改后的内容:
#
</localpathwatch><localpathwatch ="/data0/www/www">
          <remoteip ="172.16.0.4" name="www"></remoteip>
          <remoteip ="172.16.0.5" name="www"></remoteip>
          <remoteip ="172.16.0.6" name="www"></remoteip>

#
#修改31-34行,和认证相关部分,原内容为:
#
<commonparamsparams ="-artuz"></commonparamsparams>
          <auth start="false"users="root" passwordfile="/etc/rsync.pas"></auth>
          <userdefinedportstart ="false" port="874"></userdefinedportstart><!-- port=874 -->
          <timeoutstart ="false" time="100"></timeoutstart><!-- timeout=100 -->
          <sshstart ="false"></sshstart>
#
#修改后的内容为:
#
<commonparamsparams ="-aruz"></commonparamsparams>
          <auth start="true"users="rsync_bak"passwordfile="/etc/rsync.password"></auth>
          <userdefinedportstart ="false" port="874"></userdefinedportstart><!-- port=874 -->
          <timeoutstart ="true" time="100"></timeoutstart><!-- timeout=100 -->
          <sshstart ="false"/

说明:上面修改的这两部分实际上就是跟我们前面测试能否推送内容的那些命令是一样的意思。

#还需要修改一下日志记录的路径
#
#原版内容为:
#
<failLogpath="/tmp/rsync_fail_log.sh"timeToExecute="60"></sshstart><!--default every 60mins execute once-->
#
#修改后的内容为:
#
<faillog path="/usr/local/sersync/logs/rsync_fail_log.sh "timeToExecute="60"></faillog><!--default every 60mins execute once-->

说明:当同步失败后,日志记录到/usr/local/sersync/logs/rsync_fail_log.sh,并且每60分钟对失败的log进行重新同步。时间可以根据业务量进行缩短。

一份完整的sersync配置文件:

< ?xml version="1.0" encoding="ISO-8859-1"?>
<head version="2.5">
<host hostip="localhost" port="8008"></host>
<debug start="false"></debug>
<filesystem xfs="false"></filesystem>
<filter start="false">
    <exclude expression="(.*)\.svn"></exclude>
    <exclude expression="(.*)\.gz"></exclude>
    <exclude expression="^info/*"></exclude>
    <exclude expression="^static/*"></exclude>
</filter>
<inotify>
    <delete start="true"></delete>
    <createfolder start="true"></createfolder>
    <createfile start="false"></createfile>
    <closewrite start="true"></closewrite>
    <movefrom start="true"></movefrom>
    <moveto start="true"></moveto>
    <attrib start="false"></attrib>
    <modify start="false"></modify>
</inotify>

<sersync>
    <localpath watch="/data0/www/www">
        <remote ip="172.16.0.4" name="www"></remote>
        <remote ip="172.16.0.5" name="www"></remote>
        <remote ip="172.16.0.6" name="www"></remote>
    </localpath>
    <rsync>
    <commonparams params="-artuz"></commonparams>
    <auth start="true" users="rsync_backup" passwordfile="/etc/rsync.password"></auth>
    <userdefinedport start="false" port="874"></userdefinedport><!-- port=874 -->
    <timeout start="false" time="100"></timeout><!-- timeout=100 -->
    <ssh start="false"></ssh>
    </rsync>
    <faillog path="/usr/local/sersync/logs/www_rsync_fail_log.sh" timeToExecute="60"></faillog><!--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"></plugin>
</sersync>

<plugin name="command">
    <param prefix="/bin/sh" suffix="" ignoreError="true"/>  <!--prefix /opt/tongbu/mmm.sh suffix-->
    <filter start="false">
    <include expression="(.*)\.php"></include>
    <include expression="(.*)\.sh"></include>
    </filter>
</plugin>

<plugin name="socket">
    <localpath watch="/opt/tongbu">
    <deshost ip="192.168.138.20" port="8009"></deshost>
    </localpath>
</plugin>
<plugin name="refreshCDN">
    <localpath watch="/data0/htdocs/cms.xoyo.com/site/">
    <cdninfo domainname="ccms.chinacache.com" port="80" username="xxxx" passwd="xxxx"></cdninfo>
    <sendurl base="https://pic.xoyo.com/cms"></sendurl>
    <regexurl regex="false" match="cms.xoyo.com/site([/a-zA-Z0-9]*).xoyo.com/images"></regexurl>
    </localpath>
</plugin>
</head>

说明:这里也仅仅配置了一个模块[www]的sersync的自动同步。sersync的多实例和nginx,Apache类似,需要多个不同的配置文件,来做相应的修改就可以了。例如:

#因为我有3个模块所以需要3份配置文件。一一做相应的修改就可以
cp /usr/local/sersync/conf/confxml.xml /usr/local/sersync/conf/www_conxml.xml
cp /usr/local/sersync/conf/confxml.xml /usr/local/sersync/conf/bbs_conxml.xml
cp /usr/local/sersync/conf/confxml.xml /usr/local/sersync/conf/blog_conxml.xml

第七步:启动sersync!

#直接终端运行,配置文件就可以
/usr/local/sersync/bin/sersync -r -d -o /usr/local/sersync/conf/www_conxml.xml
/usr/local/sersync/bin/sersync -r -d -o /usr/local/sersync/conf/bbs_conxml.xml
/usr/local/sersync/bin/sersync -r -d -o /usr/local/sersync/conf/blog_conxml.xml
#会显示类似的结果,只要没有error一切都OK
[root@c6mini www]# /usr/local/sersync/bin/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: 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 /data0/www/www && rsync -artuz -R --delete ./  --timeout=100 rsync_backup@172.16.0.2::www --password-file=/etc/rsync.password >/dev/null 2>&1 
run the sersync: 
watch path is: /data0/www/www
#验证启动的进程
[root@c6mini ~]# ps -ef |grep sersync
root      1096     1  0 14:05 ?        00:00:00 /usr/local/sersync/bin/sersync -r -d -o /usr/local/sersync/conf/confxml_bbs.xml
root      1114     1  0 14:05 ?        00:00:00 /usr/local/sersync/bin/sersync -r -d -o /usr/local/sersync/conf/confxml_www.xml
root      1132     1  0 14:05 ?        00:00:00 /usr/local/sersync/bin/sersync -r -d -o /usr/local/sersync/conf/confxml_blog.xml
root      1211  1195  0 14:05 pts/0    00:00:00 grep sersync

第八步:配置开机自启动

#备份一下rc.local文件
cp /etc/rc.local /etc/rc.local.bak._$(date +%F)
#末尾追加sersync命令
cat >>/etc/rc.local< < 'EOF'
# resync data to 172.16.0.4,172.16.0.5,172.16.0.6
/usr/local/sersync/bin/sersync -d -o /usr/local/sersync/conf/www_conxml.xml
/usr/local/sersync/bin/sersync -d -o /usr/local/sersync/conf/bbs_conxml.xml
/usr/local/sersync/bin/sersync -d -o /usr/local/sersync/conf/blog_conxml.xml
EOF

第九步:测试sersync是否正常!

#测试方法很多,模拟人工的方式,直接在客户端上面创建文件,在服务端查看。
#这里测试使用shell批量创建大量文件来测试效果。
#
#这是批量复制一张图片,来测试性能。
for i in {1..10000};do cp /root/cp/10k.jpg /data0/www/www/10k_`echo $(date)$RANDOM|md5sum |cut -c 1-8`.jpg;done
for i in {1..10000};do cp /root/cp/20k.jpg /data0/www/bbs/10k_`echo $(date)$RANDOM|md5sum |cut -c 1-8`.jpg;done
for i in {1..10000};do cp /root/cp/50k.jpg /data0/www/blog/10k_`echo $(date)$RANDOM|md5sum |cut -c 1-8`.jpg;done
#可以写进一个.sh脚本文件里面,一起执行。

可以通过 ps -ef |grep rsync|wc -l 来查看进程数,多次查看发现这个进程是变化的。

root@c6mini www]# ps -ef |grep rsync|wc -l
20
[root@c6mini www]# ps -ef |grep rsync|wc -l
10
[root@c6mini www]# ps -ef |grep rsync|wc -l
14
[root@c6mini www]# ps -ef |grep rsync|wc -l
18
[root@c6mini www]# ps -ef |grep rsync|wc -l

说明:实际生产环境下,服务器的配置都很高,硬盘的性能都是采用硬件阵列技术,读写的性能会高许多,因此读写就很快,进程数也就多。当然这个也跟数据量有一定的关系。主要还是看机器的性能。一般来说以 DELL R710 服务器为主,在千兆网卡情况下,每秒钟同步 10-100k 的文件能达到同步 40 到 50 个。

关于sersync的参数说明:

/usr/local/sersync/bin/sersync -help
参数-d:启用守护进程模式
参数-r:在监控前,将监控目录与远程主机用rsync命令推送一遍
c参数-n: 指定开启守护线程的数量,默认为10
参数-o:指定配置文件,默认使用confxml.xml文件
参数-m:单独启用其他模块,使用 -m refreshCDN 开启刷新CDN模块
参数-m:单独启用其他模块,使用 -m socket 开启socket模块
参数-m:单独启用其他模块,使用 -m https 开启https模块
不加-m参数,则默认执行同步程序

关于sersync的插件使用

当plugin标签设置为true时候,在同步文件或路径到远程服务器之后,会调用插件。通过name参数指定需要执行的插件。目前支持的有command、refreshCDN、socket、https四种插件。其中,https插件目前由于兼容性原因已经去除,以后会重新加入。

#只调用command插件
/usr/local/sersync/bin/sersync -d -m command
#只调用refreshCDN插件:插件refreshCDN的相关配置refreshCDN 用来在同步过程中将文件发送到目地服务器后,刷新cdn接口。如果不想使用,则将start属性设为false即可。该模块根据chinaCDN的协议,进行设计,当有文件产生的时候,就向cdn解耦发送需要刷新的路径为止。其中localpath watch=“/data0/htdocs/cms.xoyo.com/site/”是需要监控的目录。cdinfo标签指定了cdn接口的域名,端口号,以及用户名与密码。sendurl 标签是需要刷新的url的前缀。regexurl 标签中,regex属性为true时候,使用match属性的正则语句匹配inotify返回的路径信息,并将正则匹配到的部分作为url一部分下面配置文件自带的意思为,如果产生文件事件为:/data0/htdoc/cms.xoyo.com/site/jx3.xoyo.com/image/a/123.txt经过上面的match正则匹配后,最后刷新的路径是:https://pic.xoyo.com/cms/a/123.txt如果regex属性为false,最后刷新的路径就是:https://pic.xoyo.com/cms/jx3.xoyo.com/images/a/123.txt
/usr/local/sersync/bin/sersync -d -m refreshCDN
#只调用socket插件:socket插件,开启该模块,则向指定ip与端口发送inotify所产生的文件路径信息
/usr/local/sersync/bin/sersync -d -m socket
#只调用https插件
/usr/local/sersync/bin/sersync -d -m https</localpathwatch></localpathwatch>
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值