简介:

Sersync 是基于 inotify 来编写的 Linux 系统文件监控工具,当监控到文件发生变化时,调用 rsync 同步文件。

类似的功能,以前有用 rsync + inotify 实现过,这次来使用一下这个同步更迅速、功能更完善的 Sersync 。

一、代码分发服务器上安装 Sersync 、Rsync

shell > cd /usr/local/src
shell > wget https://github.com/wsgzao/sersync/archive/master.zip
shell > unzip master.zip
shell > cd sersync-master && ls
inotify-tools-3.14.tar.gz README.md rsync-3.1..tar.gz sersync2..4_64bit_binary_stable_final.tar.gz

# 来到这里,你只要看一眼 README.md 你就啥都懂了

> Rsync

shell > tar zxf rsync-3.1..tar.gz
shell > cd rsync-3.1.
shell > ./configure; make; make install

> Inotify-tools

shell > tar zxf inotify-tools-3.14.tar.gz
shell > cd inotify-tools-3.14
shell > ./configure; make; make install

> Sersync ( 监控同步目录变化,调用 Rsync 同步数据 )

shell > tar zxf sersync2..4_64bit_binary_stable_final.tar.gz
shell > mv GNU-Linux-x86 /usr/local/sersync

# 安装完毕

二、节点服务器安装、配置 Rsync

shell > cd /usr/local/src
shell > wget http://rsync.samba.org/ftp/rsync/src/rsync-3.1.1.tar.gz
shell > tar zxf rsync-3.1..tar.gz
shell > cd rsync-3.1.
shell > ./configure; make; make install shell > vim /etc/rsyncd.conf uid = www-data
gid = www-data log file = /var/log/rsyncd.log list = false
read only = no
use chroot = no
ignore errors = yes
max connections = auth users = rsync
secrets file = /etc/rsync.pass # hosts allow = 192.168.1.80
# hosts deny = * # 认证的模块名
[web1]
comment = web1
path = /data/webroot/web1 [web2]
comment = web2
path = /data/webroot/web2 shell > useradd -r -s /sbin/nologin www-data
shell > mkdir -p /data/webroot/{web1,web2}
shell > chown -R www-data.www-data /data/webroot shell > echo "rsync:123456" > /etc/rsync.pass
shell > chmod /etc/rsync.pass shell > setenforce # 关闭 SELinux
shell > vim /etc/selinux/config # 永久
SELINUX=disabled # 原 enforcing
SELINUXTYPE=targeted # 另外防火墙开放 TCP shell > rsync - --daemon # 以守护进程方式启动,- 只监听 IPV4
shell > echo "/usr/local/bin/rsync -4 --daemon" >> /etc/rc.local # 加入开机启动

三、代码同步服务器测试 Rsync,配置 Sersync

1、测试 Rsync 数据同步

shell > rsync -av --delete /data/webroot/web1/ rsync@192.168.1.30::web1  # 将 web1 目录下的文件同步到 1.30 web1 模块指定的目录下
password:

# 输入密码:123456,采用下面的方法,不需要手动输入密码

shell > echo "" > /etc/rsyncd.pass
shell > chmod /etc/rsyncd.pass shell > rsync -av --delete --password-file=/etc/rsyncd.pass /data/webroot/web1/ rsync@192.168.1.30::web1

# 注意同步目录及子目录、文件权限,设为 www-data、注意认证密码文件。

2、配置 Sersync

shell > cd /usr/local/sersync
shell > cp confxml.xml web1.xml shell > vim web1.xml # 编辑配置文件 <sersync>
<localpath watch="/data/webroot/web1">
<remote ip="192.168.1.30" name="web1"/>
</localpath>
<rsync>
<commonParams params="-artuz"/>
<auth start="false" users="root" passwordfile="/etc/rsync.pas"/>
<userDefinedPort start="false" port=""/><!-- port= -->
<timeout start="false" time=""/><!-- timeout= -->
<ssh start="false"/>
</rsync>
<failLog path="/tmp/rsync_fail_log.sh" timeToExecute=""/><!--default every 60mins execute once-->
<crontab start="false" schedule=""><!--600mins-->
<crontabfilter start="false">
<exclude expression="*.php"></exclude>
<exclude expression="info/*"></exclude>
</crontabfilter>
</crontab>

# <localpath watch="/data/webroot/web1"> # 需要同步的目录
# <remote ip="192.168.1.30" name="web1"/> # 同步主机,认证模块名 ( 可以写多条 )
# <commonParams params="-artuz"/> # Rsync 同步参数
# <auth start="false" users="root" passwordfile="/etc/rsync.pas"/> # 是否开启认证,客户端开启认证,需设为 true,填写认证用户、密码文件路径
# <failLog path="/tmp/rsync_fail_log.sh" timeToExecute="60"/> # 失败日志记录
# <crontab start="false" schedule="600"> # 自带任务计划,多长时间自动同步数据,默认关闭

3、运行 Sersync

shell > nohup /usr/local/sersync/sersync2 -r -d -n  -o /usr/local/sersync/web1.xml > /usr/local/sersync/logs/rsync_web1.log >& &

# -r 启动监控前,将监控目录与远程主机同步一次
# -d 启用守护进程模式
# -n 开启同步进程的数量,默认 10 个
# -o 指定配置文件,默认 confxml.xml

# 多个监控目录,指定不同的配置文件,开启多个进程。

四、测试 Sersync + Rsync

# 代码分发服务器上,监控目录内创建文件(修改权限),增加文件内容,查看节点服务器有没有同步数据。
# 删除文件、创建目录、删除目录

# 测试发现,如果同步目录内文件权限不为 www-data,该文件可以同步到节点服务器,但是追加文件内容,则无法同步。
# 注意文件权限。

# 一个完整的流程:开发同事将代码提交到版本库-->点击上线-->数据同步到线上代码分发服务器-->通过 Sersync + Rsync 分发到-->节点服务器

Sersync + Rsync 代码分发的更多相关文章

  1. rsync+sersync实现代码同步

    APP02安装 rsync服务端 yum install rsync vim /etc/rsyncd.conf pid file=/var/rsynclog/rsyncd.pid log file=/ ...

  2. 【linux运维】rsync+inotify与sersync+rsync实时数据同步笔记

    Rsync(remote sync)远程同步工具,通过rsync可以实现对远程服务器数据的增量备份通过,但rsync自身也有缺陷,同步数据时,rsync采用核心算法对远程服务器的目标文件进行对比,只进 ...

  3. sersync + rsync 实现文件的实时同步

    这里有一点要特别注意了,就是在你完成备份之后,先不要把本地的文件都给删除了,先把服务停了之后再删除文件, 因为你已删除,检查到两边不一致,他又会把备份端给删除了.所以特别得注意了.这里吃过一次亏. 还 ...

  4. Sersync+Rsync实现触发式文件同步

    背景 通常我们在服务器上使用rsync加上crontab来定时地完成一些同步.备份文件的任务.随着业务和应用需求的不断扩大.实时性要求越来越高.一般rsync是通过校验所有文件后,进行差量同步,如果文 ...

  5. [sersync+rsync] centos6.5 远程文件同步部署记录

    针对本地文件的修改,自动同步到远程文件夹,远程备份很方面.研究了下大家的主流同步方案一般是 rsync+inotify和rsync+sersync, 我这里使用sersync的方案,当然大部分都是参照 ...

  6. CentOS 7 Sersync+Rsync 实现数据文件实时同步

    rsync+inotify-tools与rsync+sersync架构的区别? 1.rsync+inotify-tools inotify只能记录下被监听的目录发生了变化(增,删,改)并没有把具体是哪 ...

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

    sersync+rsync实现服务器文件实时同步 一.为什么要用rsync+sersync架构? 1.sersync是基于inotify开发的,类似于inotify-tools的工具 2.sersyn ...

  8. sersync+rsync原理及部署

    标签:sersync+rsync部署文档 原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 .作者信息和本声明.否则将追究法律责任.http://liubao0312.blog.51ct ...

  9. sersync+rsync实时数据同步

    sersync+rsync实时数据同步 1.相关背景介绍 前面有关文章配置实现了rsync增量同步以及配置为定时同步,但是在实际生产环境中需要实时的监控数据从而进行同步(不间断同步),可以采取inot ...

随机推荐

  1. JSP学习(一)JSP基础语法

    JSP基础语法 1.JSP模版元素 JSP页面中的HTML内容称之为JSP模版元素. JSP模版元素定义了网页的基本骨架,即定义了页面的结构和外观. <%@ page language=&quo ...

  2. Oracle中Inner join和Where的区别

    1 .Where子句中使用的连接语句,在数据库语言中,被称为隐性连接.Inner join--on子句产生的连接称为显性连接.(其他Join参数也是显性连接)Where 和Inner join产生的连 ...

  3. Asp.net Global 定时执行

    在复杂的业务应用程序中,有时候会要求一个或者多个任务在一定的时间或者一定的时间间隔内计划进行,比如定时备份或同步数据库,定时发送电子邮件,定期处理用户状态信息,支付系统中定期同步异常账单等等,我们称之 ...

  4. {Reship}{Sparse Representation}稀疏表示入门

    声明:本人属于绝对的新手,刚刚接触“稀疏表示”这个领域.之所以写下以下的若干个连载,是鼓励自己不要急功近利,而要步步为赢!所以下文肯定有所纰漏,敬请指出,我们共同进步! 踏入“稀疏表达”(Sparse ...

  5. BZOJ4543 [POI2014]Hotel加强版

    题意 有一个树形结构,每条边的长度相同,任意两个节点可以相互到达.选3个点.两两距离相等.有多少种方案? 数据范围:n<=100000 分析 参照小蒟蒻yyb的博客. 我们先考虑一个\(O(n^ ...

  6. php array_push 与 $arr[]=$value 性能比较

    1.array_push方法 array_push 方法,将一个或多个元素压入数组的末尾. int array_push ( array &$array , mixed $var [, mix ...

  7. Mysql中五级权限小结

    mysql的权限控制主要是通过mysql库下的db,user,host,table_priv,column_priv表控制. 由于权限信息数据量比较小,所以mysql在启动时会将所有的权限消息加载到内 ...

  8. 1.Django入门小Demo

    1.Django安装 (1)前提:已安装python环境 (2)打开命令行输入:pip install Django==2.1.3 (3)打开Pycharm,在File--Setting--Proje ...

  9. 关于angular.extend的用法

    ng中的ng-function中会有些方法,便于我们进行js代码的编写 关于angular.extend(dst, src);通过从src对象复制所有属性到dst来扩展目标对象dst.你可以指定多个s ...

  10. 给DB2增加删除字段二三事

    加字段用这个,CS.TG表名,LINE2_TYPE字段名,CHAR(1)字段类型 ALTER TABLE CS.TG ADD COLUMN LINE2_TYPE CHAR(1); 要是加错了用以下语句 ...